我试图使用MySQLi查询获取数据。 请检查我的SQL查询,我收到If条件的错误。 我添加误差,其旁请检查MySQL查询
如果条件
当得到显示到控制台
<?php
$id = $_GET['id'];
include("../include/connection_string.php");
$sql = mysqli_query($db, "SELECT pages, main_id FROM dhms_index_table where main_id='"+$id+"'");
if(mysqli_num_rows($sql)){ // Showing error here " Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result"
$data = array();
while($row = mysqli_fetch_array($sql)){
$data[] = array(
'pages' => $row['pages'],
'main_ID' => $row['main_id']
);
}
header('Content-type: application/json');
echo json_encode($data);
}
?>
connections_string.php
$server = 'localhost';
$username ="root";
$passwd ='';
$Dbase = 'og_dhms';
$db = @mysqli_connect($server,$username,$passwd)
or die("Could not connect database");
@mysqli_select_db($db, $Dbase)
or die("Could not select database");
add'echo mysqli_error();'if if –
我猜测查询失败或连接不正确。向我们显示'connection_string。php' – RiggsFolly
也看看你的php错误日志,并告诉我们完整的错误信息 – RiggsFolly