Page 1 of 1

how can i check to see if data exists before pulling it out?

Posted: Tue Jul 17, 2007 4:21 pm
by suthie
I use this code to get data from a database:

Code: Select all

$sql = "SELECT * from dailyvibe WHERE userlink='$username' ORDER BY postid DESC";
$result = mysql_query($sql) or print ("Can't select entry from table php_blog.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)){     
$date = stripslashes($row['timestamp']);    
$title = stripslashes($row['title']);    
$entry = stripslashes($row['entry']);

...other stuff...

}
How can i make it so if there is no data with the correct username, it gives a message saying no data was found?

Posted: Tue Jul 17, 2007 5:06 pm
by Jenk

Code: Select all

if (!mysql_num_rows($result))
    echo "No data found.";