我在我的網站上有關於事件管理的數據表,我想根據事件的「名稱」和「類型」將搜索功能添加到表中。警告:在&mysqli_query()中用零除法:空查詢
這裏是我的代碼,通過我得到的錯誤,並在用戶提交我需要的頁面刷新和篩選結果表的搜索,但這段代碼打開一個新頁面,完全乾淨樣式表:
我需要我的頁面根據用戶在搜索文本框中輸入的內容來篩選我的表格 您可以在以前的問題中看到我的表格,我詢問了 請提供簡單的答案,我是php的新手。
<form action="search.php" id="searchform" method="POST" class="searchbox-container">
<input type="text" id="searchbox" placeholder="Search" name="searchbox" class="searchbox" />
<select name="select" id="select">
<option value="type">Type</option>
<option value="name">Name</option>
</select>
<input type="submit" name="search" class="searchbox-btn" value="Go" />
<?php
if(isset($_POST['searchbox']) && $_POST['searchbox'] !=""){
$search=preg_replace('#[^a-z 0-9?!]#i','',$_POST['searchbox']);
$user="admin";
$pass="neehahs";
$host="localhost";
$db_name="eventregisteration";
$con=mysqli_connect($host, $user, $pass, $db_name);
if(mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if($_POST['select']=="type"){
$sqlcommand="SELECT * FROM eventform WHERE event_type LIKE "%$search%"";
}
elseif($_POST['select']=="name"){
$sqlcommand="SELECT * FROM eventform WHERE event_name LIKE "%$search%""; ===>> this line give Division by zero error
}
$sqldata=mysqli_query($con,$sqlcommand) ==>> this line give mysqli_query(): Empty query error
or die("Error Getting Data");
$count=mysqli_num_rows($sqldata);
if($count>1){
while($row=mysqli_fetch_array($sqldata)){
echo "<table>";
echo "<tr align=center><td>";
echo $row['event_code'];
echo "</td><td>";
echo $row['event_name'];
echo "</td><td>";
echo $row['event_type'];
echo "</td><td>";
echo $row['event_level'];
echo "</td><td>";
echo $row['start_date'];
echo "</td><td>";
echo $row['end_date'];
echo "</td><td>";
echo $row['points'];
echo "</td><td>";
echo $row['pic'];
echo "</td><td>";
echo $row['video'];
echo "</td><td>";
echo $row['description'];
echo "</td></tr>";
}
echo "</table>";
}else{
$search_output="<hr/>0 Results for<strong>$sqldata</strong><hr/>$sqlcommand";
}
}
?>
感謝的人師的錯誤已經解決,但我得到捕致命錯誤:類mysqli_result的對象不能轉換爲字符串上線>>>> $ search_output =「
0結果$ SQLDATA
$ SqlCommand的」; – Shane
@Shane這是因爲'$ sqldata'是一個資源而不是字符串。你到底想輸出什麼? – jszobody
我希望根據用戶的搜索功能篩選表格 – Shane