私はこのサイトに不慣れで、誰かが正しい道を案内してくれることを願っています. 私はPostgreSQLとphpを使用しています。今、時間の開始と終了を表示する必要があります。しかし、なぜかうまく表示されません。これを行うためのヘルプガイドをいくつか読みましたが、その部分では失敗しました。次のデータを含む2つのテーブルがあります。
表1
index product qualityno value
1 Mangoes aaa1 10
2 Bananas bbb2 10
3 Apples ccc3 10
4 Orange ddd4 10
5 Grapes eee5 10
6 Melons fff6 10
7 Lemons ggg7 11
8 Berry hhh8 11
9 Strawberry iii9 11
テーブル2
index qualityno Date Start End
4 ddd4 04/08/13 10:05:00 AM 11:15:00 AM
5 eee5 04/09/13 03:11:00 PM 04:25:00 PM
6 fff6 05/20/13 01:15:00 PM 01:30:00 PM
7 ggg7 05/20/13 08:15:00 AM 09:10:00 AM
1 つのテーブル内に両方のテーブル情報を表示したいので、クエリ I を変更せずに 2 つのクエリを作成しました。
クエリⅠ
$sql1 =select * from table1 where value=10 or value=11
$result1 =pg_query($sql1);
クエリⅡ
$sql2 =select * from table2 t2
join table1 t1 on t1.index = t2.index
and t1.qualityno =t2.qualityno
$result2 =pg_query($sql2);
php 内で html を使用して両方を組み合わせます。
while(($row1 =pg_fetch_array($result1)) && ($row2=pg_fetch_array($result2)))
{
echo "<tr>";
echo "<td> " . $row1["index"] . "</td>";
echo "<td> " . $row1["product"] . "</td>";
echo "<td> " . $row1["qualityno"] . "</td>";
echo "<td> " . $row1["value"] . "</td>";
echo "</tr>";
}
//I used the code below to insert the date, start and end time
//I'm hoping to print 0 if index number and qualityno no match
//I echo date first test my code if both index and qualityno existed.
if(($row2[index] !=$row1[index]){ echo "<td>0</td>";}
else{echo "<td> " . $row["Date"] . "</td><td>".$row2[start]."</td><td>".$row2[end]."</td>"; }
しかし、一致しないphpクエリを実行するたびに、$row2が上に移動し、インデックス= 1を占有し、ゼロ「0」を挿入しないため、結果が間違っており、インデックスが間違っています。
index product qualityno value
1 Mangoes aaa1 10
4 04/08/13 10:05:00 AM 11:15:00 AM //wrong match
2 Bananas bbb2 10
5 04/09/13 03:11:00 PM 04:25:00 PM //wrong match
3 Apples ccc3 10
6 05/20/13 01:15:00 PM 01:30:00 PM //wrong match
4 Orange ddd4 10
5 Grapes eee5 10
6 Melons fff6 10
7 Lemons ggg7 11
テーブルに次のアイテムを表示したい:
index product qualityno value
1 Mangoes aaa1 10
0
2 Bananas bbb2 10
0
3 Apples ccc3 10
0
4 Orange ddd4 10
04/08/13 10:05:00 AM 11:15:00 AM
5 Grapes eee5 10
04/09/13 03:11:00 PM 04:25:00 PM
6 Melons fff6 10
05/20/13 01:15:00 PM 01:30:00 PM
7 Lemons ggg7 11
05/20/13 08:15:00 AM 09:10:00 AM
8 Berry hhh8 11
0
9 Strawberry iii9 11
0
//I was hoping that my code below can dispaly the list,
//unfortunately its not successful
//if(($row2[index] !=$row1[index]){ echo "<td>0</td>";}
//else{echo "<td> " . $row["Date"] . "</td>"; }
私の説明がわかりにくい場合は、遠慮なく質問してください。数日間行き詰まっており、助けが必要なので、これを理解するのを手伝ってください。前もって感謝します。