3 つの mysql テーブルがあります。
1. inbox - ID(int), FileNo(varchar), FolioNo(smallint), Reference(varchar), Received(date), Sent(date), Description(text), Forwarded(varchar),...etc
2. outbox - ID(int), Reference(varchar), Sent(date), FileNo(varchar), FileName(varchar), FolioNo(smallint), Description(text), Receiver(varchar),...etc
3. status - ID(int), SN(int), Date(date), Minutes(varchar), Instructed(varchar), Responsible(varchar), Action(boolean), FileNo(varchar),...etc
FileNo を使用してこれら 3 つのテーブルを結合し、次のように FolioNo で並べ替えます。
File No: 123
File Name: abc
Folio No | Date | Description | Sender/Receiver | Minutes | Instructed | Responsible | Action
----------------------------------------------------------------------------------------------------
1 | 13-09-08 | Something | Someone | Something | Someone | Someone | Yes
2 | 13-09-10 | Something | Someone | Something | Someone | Someone | Yes
......etc
PHPでの私のSQLクエリは次のとおりです。
$sql="SELECT * FROM
(SELECT I.FileNo, I.FolioNo, I.Received AS Date, I.Description, I.Forwarded
FROM Inbox I WHERE I.FileNo='$ID'
UNION SELECT O.FileName, O.FolioNo, O.Sent AS Date, O.Description, O.Receiver
FROM Outbox O WHERE O.FileNo='$ID'
UNION SELECT S.Date, S.Minutes, S.Instructed, S.Responsible, S.Action
FROM Status S WHERE S.FileNo='$ID')
AS A ORDER BY A.FolioNo";
出力、
<table>
<tr><th>Folio No</th><th>Date</th><th>Description</th><th>Sender/ Receiver</th><th>Minutes</th><th>Instructed</th><th>Responsible</th><th>Action</th></tr>
<?php
while ($list = mysql_fetch_assoc($result)) {
echo "<tr><td>" . $list['FolioNo'] . "</td><td>" . $list['Date'] . "</td><td>" . $list['Description'] . "</td><td>" . $list['Receiver'] . "</td><td>" . $list['Minutes'] . "</td><td>" . $list['Instructed'] . "</td><td>" . $list['Responsible'] . "</td><td>" . ($list['Action']=1?'Yes':'No') . "</td></tr>";
$x++;
}
echo "</table>";
?>
しかし、これはエラーを示しています。
Notice: Undefined index: Receiver in C:\xampp\htdocs\sp\viewMinutes.php on line 145 Notice: Undefined index: Minutes in C:\xampp\htdocs\sp\viewMinutes.php on line 145 Notice: Undefined index: Instructed C:\xampp\htdocs\sp\viewMinutes.php の 145 行 通知: 未定義のインデックス: C:\xampp\htdocs\sp\viewMinutes.php の責任 145 行の通知: 未定義のインデックス: C:\xampp\ の受信者145 行目の htdocs\sp\viewMinutes.php 注意: 未定義のインデックス: C:\xampp\htdocs\sp\viewMinutes.php の分 145 行目の注意: 未定義のインデックス: C:\xampp\htdocs\sp\viewMinutes で指示されています。 php on line 145 Notice: Undefined index: Responsible in C:\xampp\htdocs\sp\viewMinutes.php on line 145 Notice: Undefined index: Receiver in C:\xampp\htdocs\sp\viewMinutes.php on line 145 Notice:未定義のインデックス: C:\xampp\htdocs\sp\viewMinutes.php の 145 行目の分 注意:Undefined index: Instructed in C:\xampp\htdocs\sp\viewMinutes.php on line 145 Notice: Undefined index: Responsible in C:\xampp\htdocs\sp\viewMinutes.php on line 145
FOLIO NO | DATE | DESCRIPTION | SENDER/ RECEIVER | MINUTES | INSTRUCTED | RESPONSIBLE | ACTION
-------------------------------------------------------------------------------------------------------------------------------------
1 | 13-09-08 | Something | | | | | Yes
2 | 13-09-08 | Something | | | | | Yes
| 13-09-08 | Something | | | | | Yes
Something| Someone | Anyone | Yes
ここで何が問題なのですか?
アップデート:
$sql = "SELECT
Inbox.FolioNo, Inbox.Received, Inbox.Description, Inbox.Forwarded,
Outbox.FileNo, Outbox.FileName, Outbox.FolioNo, Outbox.Sent, Outbox.Description, Outbox.Receiver,
Status.Date, Status.Minutes, Status.Instructed, Status.Responsible, Status.Action
FROM Status INNER JOIN Outbox ON Status.FileNo = Outbox.FileNo
INNER JOIN Inbox ON Status.FileNo = Inbox.FileNo WHERE Status.FileNo = '$ID' ORDER BY Outbox.FolioNo ASC";