我試圖使用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