簡體   English   中英

回復:MySQL服務器未返回正確的輸出

[英]Re: MySQL server not returning correct output

我有這個問題中提到的類似問題: 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';
    }
}
?>

在我的數據庫中創建的表在這里:

while loop 3開始生成輸出,並且必須通過array方法& Table1與輸出進行比較。 如果在array找到Table1 ,則它應該回顯Table not available但是它回顯Table available
為什么array不起作用?

如果給定鍵在數組中設置,則array_key_exists()返回TRUE。 鍵可以是數組索引的任何可能值。 我不認為你正在檢查重點數組中存在的這樣的array_key_exists不能用在這里使用in_array()而不是array_key_exists

$array  = array("table1","table2","tabl3");
if(in_array('table2',$array)){
  echo "Table not available";   
} else {
 echo "Table available";    
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM