gpt4 book ai didi

php - 回复 : MySQL server not returning correct output

转载 作者:行者123 更新时间:2023-11-29 06:11:43 25 4
gpt4 key购买 nike

我遇到了这个问题中提到的类似问题:MySQL server not returning correct output但是即使问题发生了一些变化,问题也没有在那个特定的问题中解决。

<?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';
}
}
?>

在我的数据库中创建的表在这里:Table

while 循环 生成 3 个输出,并且通过 array 方法 & Table1 必须与输出进行比较。如果在 array 中找到 Table1,它应该回显 Table not available 但它正在回显 Table available。< br/>为什么 array 不起作用?

最佳答案

array_key_exists() returns TRUE if the given key is set in the array. key can be any value possible for an array index. I dont think you are checking key present in the array so the array_key_exists cannot be used here use in_array() instead of array_key_exists

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

关于php - 回复 : MySQL server not returning correct output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com