3
在我的代碼中搜索記錄時,我在while塊中得到錯誤,它沒有檢索記錄。我沒有使用bind_result,因爲要檢索的列數是45. 請幫助我,我在這裏錯了。使用mysqli預處理語句獲取所有記錄檢索中的錯誤
<?php
/* ___Search & display record with MySQLi Prepared Statements ___*/
if(isset($_GET['search'])) {
$cname=$_GET['cname'];
$cname=preg_replace('/\s+/','',$cname);
if($cname==""){
unset($cname);
$error="Plese enter the company name";
}
else {
require_once '../includes/mysqli_dbconnect.php';
$cname = '%'.$cname.'%';
$query1 = "SELECT * FROM company WHERE cname LIKE ? ORDER BY cname DESC";
$stmt=$dbLink->prepare($query1);
if($stmt===false){
trigger_error('Query Failed'. $query1 . 'Error: ' . $dbLink->error, E_USER_ERROR);
}
$stmt->bind_param('s',$cname);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$rs=$stmt->get_result();
while($row=$rs->fetch()){
//here number of columns to show are 45.
echo 'ID: '. $row['id']. '<br/>';
echo 'Company: '. $row['cname']. '<br/>';
}
}else{
echo 'No Record Found';
}
$stmt->close();
$dbLink->close();
}
}
?>
'在我的搜索記錄的代碼中,我在while塊中收到錯誤,並且會出現什麼錯誤? – Dorvalla