0

Hi I have this working for the query to output the result but the if zero results echo is not working, and I cnat see why, if anyone can help please, there is no error that comes up and to test there is nothing in the database table, it works when there is something in and echos out the result but not when the result is 0

$result = mysql_query("whatever query") or trigger_error(mysql_error().$sql);
while($row = mysql_fetch_array($result)){
 if(mysql_num_rows($result)==0) 
{
  echo 'there is none....';
  }     
    else
echo 'my stuff that works';
}
2
Contributors
5
Replies
8
Views
4 Years
Discussion Span
Last Post by mpc123
0

You should put the if on the outside like this:

$result = mysql_query("whatever query") or trigger_error(mysql_error() . $sql);
if (mysql_num_rows($result) == 0) 
{
    echo 'there is none....';
}
else
{
    while($row = mysql_fetch_array($result))
    {
        echo 'my stuff that works';
    }
}
0

Sorry my fault i did something wrong from your info... thanks for that info

Also if i want to echo $txt1 $txt2 in that ($result)==0 echo what format would they have to be in please eg at the moment i have

echo '$txt1 $txt2...';

but the result just echos $txt1 $txt2... onto the page rather than what they should

1

Its ok thanks i sorted it with ' . $txt1 . ' ' . $txt2 . '

Thanks for your help resolving the original problem

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.