views:

217

answers:

3

The following code continues to be displayed even if there are entries in my database and I don't understand why. Am I missing something? I'm not sure if this makes sense, but help would be great. :)

if($numrows==0)
{
echo"<h3>Results</h3>";
echo"<p>Sorry, your search: &quot;".$escaped."&quot; returned zero results</p>";
}
+2  A: 

how do you get $numrows? It can be the mistake.

What I usually do is:

if($numrows > 0 ){

  // Code

}else{
  echo"<h3>Results</h3>";
  echo"<p>Sorry, your search: "".$escaped."" returned zero results</p>";
}
fesja
Oh. Thank you. I would just put my query where you have //Code right? Because when I do that it just displays the else statement. :/
Holly
can you paste your query and how you get the $numrows value?
fesja
No //code is what you want to do when you have some rows. You have to query the DB first, in order to get numrows.
barfoon
+2  A: 

Try:

echo "'$numrows'";

Directly above the if statement. If output is not '0', then the problem is how you're assigning 0 to $numrows.

Babiker
The if block actually would currently get executed if $numrows were null (because the == operator doesn't compare types), but it would not if she changed it to if($numrows === 0)
John Rasch
Thaks John. You're right.
Babiker
+5  A: 

If the code you're having a problem with is the same as quoted in your previous question... then the problem is here:

$numresults=mysql_query($query);
$numrows=mysql_num_rows(numresults);

You're missing a $ before numresults on the second line.

bdonlan
+1 - nice find!
John Rasch