我有一个名为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'',这意味着它返回的所有表格都不可用,请详细解释你想要达到的目标。 –