我回到PHP和MySQL編碼,我有一個搜索頁,使用2 while while循環返回表中的某些行。PHP while while循環內循環只返回有限行
第一個while循環搜索數據庫,第二個搜索第二個DB查找註冊上的匹配以確定設備的類型。但是,腳本正在工作,但當第一個while循環返回2個以上結果時,第二個while循環僅顯示設備上的前2個返回值,任何幫助都將受到歡迎。
$connect = mysql_connect("$dbhost", "$dbuname", "$dbpass") or die("Couldn't connect.");
$db = mysql_select_db($db_name, $connect) or die("Couldn't select database.");
$query = "SELECT * FROM `db1` WHERE `dest_id` =$ap ORDER BY video_date DESC, operator_name, operator_tail ASC";
$result = mysql_query($query,$connect) or mysql_error();
while ($r = mysql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
$time_update = $r[video_date];
$str_time = date('M. d, Y', $time_update);
echo ("<tr><td bgcolor='$row_color'> <a href='$server?al=$r[operator_id]'>$r[operator_name]</a>
</td><td bgcolor='$row_color' align='center'> <a href='$r[operator_ICAO]$r[flight_num]' target='_blank'>$r[flight_num]</a>
</td><td bgcolor='$row_color'> <a href='$r[operator_tail]' target='_blank'>$r[operator_tail]</a>
</td><td bgcolor='$row_color' align='center'> <a href='$r[video_url]' target='_blank'>$r[video_url]</a>
</td><td bgcolor='$row_color' align='center'>");
$connect2 = mysql_connect("$dbhost", "$dbuname", "$dbpass") or die("Couldn't connect.");
$query2 = "SELECT * FROM `plane` WHERE `plane_id` =$r[plane_id]";
$result2 = mysql_query($query2,$connect2) or mysql_error();
while ($q = mysql_fetch_array($result2)) {
echo (" $q[plane_type]");
}
mysql_close($connect2);
echo (" </td><td bgcolor='$row_color' align='center'> $str_time
</td><td bgcolor='$row_color' align='center'> <a href='$server?ap=$r[dest_id]'>$r[dest_name]
</td><td bgcolor='$row_color' align='center'> $r[vtype_name]
</td> </tr>");
$row_count++;
}
mysql_close($connect);
1)你沒有連接到再次分貝。 2)你應該考慮使用PDO或mysqli_ *作爲mysql_ *已被棄用 – ElefantPhace
你沒有選擇數據庫在$ connect2,並且@ElefantPhace說,當你回到PHP,更新你的知識,你應該開始使用mysqli或PDO作爲mysql_ *函數已被棄用 – CodeBird
我認爲他的意思是第二張表,不一定是第二個數據庫,但我可能是錯的... – ElefantPhace