Reputation: 3
How would I do let the user know if there wasnt any rows found? And if it finds (for example) 26 rows I want it to print that it found 26 hits (Your search for "hey" gave 26 results)
$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>";
}
Upvotes: 0
Views: 66
Reputation: 33408
Use 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>";
}
}
Upvotes: 3