我需要一些幫助來加入下面的查詢,因爲我相信這是超級重的,while循環內其他while循環...一團糟,對吧?! :(Mysql複雜查詢加入
這工作,但如果有人可以幫助加入到只有一個查詢這樣的:
$query_1 = mysql_query("SELECT * FROM booking_reservation WHERE reservation_confirmed = '1' AND (reservation_name LIKE '$data%' OR reservation_phone LIKE '$data%' OR reservation_email LIKE '$data%')");
while ($row = mysql_fetch_array($query_1)) {
$calendar_id = $row['calendar_id'];
$query_2 = mysql_query("SELECT * FROM booking_calendars WHERE calendar_id = '$calendar_id'");
$row_2 = mysql_fetch_array($query_2);
$slot_id = $query_1['slot_id'];
$query_3 = mysql_query("SELECT * FROM booking_slots WHERE slot_id = '$slot_id'");
while ($row_3 = mysql_fetch_array($query_3)) {
echo '<tr><td>' . htmlentities($row2['slot_date']) . '</td><td>' . htmlentities($query_3['slot_time_from']) . '</td><td>' . htmlentities($query_1['reservation_name']) . '</td><td>' . htmlentities($query_3['calendar_title']) . '</td><td>' . htmlentities($query_1['reservation_phone']) . '</td><td>' . htmlentities($query_1['reservation_email']) . '</td></tr>';
}
}
停止使用不推薦使用的'mysql_ *'函數,改爲使用PDO/MySQLi。 – Raptor
我認爲這可能是題外話題,因爲它屬於http://codereview.stackexchange.com/ – Pred
這個問題似乎是主題(不幸)。 – RandomSeed