Question

I'm trying to set up a handler so when i get 0 results it displays a message saying no results found. I sort of have this working but i'm facing 2 issues at the moment.

When i get 0 Results it does display the no results found but it also displays the following error:

Warning: mysqli_query() expects parameter 2 to be string, object given in /customers/b/6/d/herculesdjs.co.uk/FETCH.PHP on line 74

line 74 is this:

$fetch_row = mysqli_query($con,$result);

this is the full script minus the connection info. $City is defined by a drop down box. This has been tested and works fine:

$result = mysqli_query($con,
sprintf("SELECT * FROM `SouthYorkshire` WHERE  `city_id` = '%s'",
       preg_replace("[^0-9]","", $city)));


// Handle Null Results.
$fetch_row = mysqli_query($con,$result); 
$numrows = $fetch_row[0]; 
if($numrows==0) 
{ 
echo "<div id=\"NoResults\">";
echo "There are no clubs in this area, Why not come back another day. Know of one in this area? Why not submit it via Contact Us.";
echo "</div>";
}

while($row = mysqli_fetch_array($result))
{
echo "<div id=\"Results\">";
echo "<div id=\"theclub\">";
echo "<div class=\"ClubName\">";
echo $row['EstName'];
echo "</div><br>";
echo "<div class=\"Location\">";
echo $row['EstAddress2'];
echo "</div>";
echo "<br>";
echo "<div id=\"website\"><a href=\"#\"><img src=\"photos/more-info.png\" width=\"75\" height=\"25\"/></a> <a href=\"" . $row['EstWebsite'] ."\" target=\"_blank\"><img src=\"photos/visit-website-button.png\" width=\"75\" height=\"25\" /></div></a></div>";
echo "<br>";
}
echo "</div>";`

Another issue i'm having is if there are results in the database it doesn't display the Warning. It displays the results found but it also displays the There are no clubs message.

Any suggestions?

Was it helpful?

Solution

Goodness knows why you thought that this was the correct way to obtain the number of records returned by your query: it's complete nonsense.

You should get rid of $fetch_row and instead use mysqli_num_rows():

$numrows = mysqli_num_rows($result);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top