如果找不到任何行,我该如何让用户知道? 如果它找到(例如)26行我希望它打印它发现26次点击(你搜索“嘿”给出了26个结果)
$name = mysql_real_escape_string($_POST['player_name']);
$q = mysql_query("SELECT * FROM players WHERE name LIKE '%$name%'");
while ($row = mysql_fetch_array($q)) {
$name = $row['name'];
echo "<ul>\n";
echo "<li>" . "<a href=\"player-info.php?id=\">" .$name . " </a></li>\n";
echo "</ul>";
}
答案 0 :(得分:3)
使用mysql_num_rows
:
$rowCount = mysql_num_rows($q);
if ($rowCount === 0)
{
echo 'Found nothing!';
}
else
{
echo "Found $rowCount rows!";
while ($row = mysql_fetch_array($q))
{
$name = $row['name'];
echo "<ul>\n";
echo "<li>" . "<a href=\"player-info.php?id=\">" .$name . " </a></li>\n";
echo "</ul>";
}
}
答案 1 :(得分:1)
答案 2 :(得分:1)
$numberOfResults = mysql_num_rows($q);