我有一個名爲booktable
的表,如截圖所示。當我運行查詢輸出是Table availabe
雖然它應該是Table not available.
最初,我試圖檢查條件,而不使用array_key_exists
和解決方案在下面提到,但沒有一個工作。MySQL服務器沒有返回正確的輸出
<?php
require 'dbconnect.php'; //connection to db is success
$search = "SELECT Table_list FROM booktable WHERE status='booked'";
$table_query = mysqli_query($dbconnect,$search);
$row_check = mysqli_num_rows($table_query);
if($row_check>=1){
$tables = array();
while($row=mysqli_fetch_assoc($table_query)){
$output = $row['Table_list'].'<br>';
echo $tables[] = $output; //returns o/p: Table1, Table2, Table3
}
if(array_key_exists('Table1',$tables)){ //trying to check if 'Table1' is in the array
echo 'Table not available'; //if 'Table1' exists should echo this line
}else{
echo'Table available';
}
}
?>
如果我把array_key_exists
部分內while loop
不把循環內的說法,即有在O/P沒有變化的O/P是相同的。
所以,我試圖採取這種方法,但我沒有像以前那樣得到正確的o/p。這種方法有什麼問題?
嘗試像,如果($輸出== '表1') –
@ Kaushal國王仍然得到同樣的O/P,沒有變化。 – 007mrviper
你已經在查詢'status ='booked'',這意味着它返回的所有表格都不可用,請詳細解釋你想要達到的目標。 –