我期望能夠使用表單搜索SQL數據庫並在屏幕上輸出查找結果。打印SQL查詢結果PHP
這是我的代碼:
$query = "SELECT * FROM documents WHERE DocumentName = '%".$DocumentName."%'AND county = '".$county."' OR acreage = '".$acreage."' AND grantor = '".$grantor."' OR grantee = '".$grantee."' ORDER by 'DocumentName'" ;
$result=$db->query($query);
$num_results=$result->num_rows;
echo "<p>Number of documents found: ".$num_results."</p>";
for($i=0; $i <$num_results; $i++){
$row=$result->fetch_assoc();
echo"<p>".($i+1).".County: ";
echo htmlspecialchars(stripslashes($row['county']));
echo "<br />Acreage: ";
echo stripslashes($row['acreage']);
echo "<br />Grantor: ";
echo stripslashes($row['grantor']);
echo "<br />grantee: ";
echo stripslashes($row['grantee']);
echo "<br />Lessor: ";
echo stripslashes($row['DocumentName']);
echo "<br />PDF: ";
echo stripslashes ("<a href=".$row['PDF'].">" .$row['PDF'] . "</a><br>");
echo "</p>";
}
$result->free();
$db->close();
它選擇並輸出該信息。事情是我需要人們能夠將一個字段留空搜索表單,但是這會導致顯示所有數據。如果他們在縣裏輸入並且留下一切空白,我希望它只提取縣裏的記錄。
'DocumentName ='%「。$ DocumentName。」%''=>'DocumentName ='「。$ DocumentName。」''' –