我有搜索查询 mysql,但由于 SQL INJECTION 我将代码更改为 MySqli。我用了
if(mysql_num_rows($result)>= 1)
之前,我把它改成
if(($result->num_rows)>= 1)
我的问题是即使查询中有匹配值,它总是回显没有结果。这是为什么?
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query="SELECT *,SUM(unit_cost*quantity) AS total_amount FROM procurement WHERE counter LIKE '%".$search."%'
OR item_description LIKE '%".$search."%' OR fund_source LIKE '%".$search."%' OR quantity LIKE '%".$search."%' OR mode_of_procurement LIKE '%".$search."%'
OR division LIKE '%".$search."%' OR section LIKE '%".$search."%' GROUP BY counter";
if(($result->num_rows)<= 0){
echo "</br><div style='margin:0 auto;background:#fff;padding:3px;color:#2086e4;font-size:11px;font-weight:bold;text-align:center;'>
No Result for :<font color='red' style='text-transform:uppercase'> ".$search."</div>";
//echo 'No Result for <font color="red">'.$search.'</font>';
}
if(($result->num_rows)>= 1){
echo'</br><div style="margin:0 auto;background:#fff;padding:3px;color:#2086e4;font-size:11px;font-weight:bold;text-align:center;">
Result for :<font color="red" style="text-transform:uppercase"> '.$search.'</font></div>';
echo"<div id='id3' style='margin-top:10px;'><table id='tfhover' class='tftable' border='1 style='text-transform:uppercase;'>
<thead>
<tr>
<th></th><th>Item Description</th>
<th>Fund Source</th>
<th>Unit</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Total Amount</th>
<th>Mode of Procurement</th>
<th>Supplier</th>
<th>P.O #</th>
<th>P.O Date</th>
<th>Division</th>
<th>Section</th>
</tr></thead><tbody>";
while($row = $result->fetch_assoc()){
echo'<tr>
<td><a href="'.$_SERVER['PHP_SELF'].'?pn='.$row["counter"].'" onclick="return confirm(\'Really want to delete?\');"><img src="images/del.png" border"0" width="15" height="15"></a></td>
<td>'.$row['item_description'].'</td>
<td>'.$row['fund_source'].'</td>
<td>'.$row['unit'].'</td>
<td>'.$row['unit_cost'].'</td>
<td>'.$row['quantity'].'</td>
<td>'.$row['total_amount'].'</td>
<td>'.$row['mode_of_procurement'].'</td>
<td>'.$row['supplier'].'</td>
<td>'.$row['po_number'].'</td>
<td>'.$row['po_date'].'</td>
<td>'.$row['division'].'</td>
<td>'.$row['section'].'</td></tr></tbody>';
}
}
else{
}
?>