我正在尝试创建一个迷你 PHP 搜索引擎,它只是在两个不同的表中搜索并在另一个表下显示一个表的结果。但我遇到了一个错误。这是我设置查询的地方。
$var = $_GET['q'];
$trimmed = trim($var);
$get_fighters = "
SELECT *
FROM fighters
WHERE name LIKE '%$trimmed%'
ORDER BY name ASC";
$get_events = "
SELECT *
FROM events
WHERE event_name LIKE '%$trimmed%'
ORDER BY date DESC";
$search_result_fighters = mysql_query($get_fighters);
$search_result_events = mysql_query($get_events);
$check_results_fighters = mysql_num_rows($search_result_fighters);
$check_results_events = mysql_num_rows($search_result_events);
这是我返回战士的地方(有效)
if ($check_results_fighters == 0) {
echo "<tr>";
echo "<td colspan='6'>" . "No Fighters Found." . "</td>";
echo "</tr>";
}
else if ($check_results_fighters != 0) {
while($row = mysql_fetch_array($search_result_fighters)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
}
这是我返回事件的地方,但它不起作用。我收到错误:警告:mysql_num_rows() 期望参数 1 是资源,在第 30 行的 C:\xampp\htdocs\search.php 中给出的布尔值
if ($check_results_events == 0) {
echo "<tr>";
echo "<td colspan='6'>" . "No Events Found." . "</td>";
echo "</tr>";
}
else if ($check_results_events != 0) {
while($row = mysql_fetch_array($search_result_events)) {
echo "<tr>";
echo "<td>" . $row['event_name'] . "</td>";
echo "</tr>";
}
}
第 30 行很简单:
$check_results_events = mysql_num_rows($search_result_events);