Click to See Complete Forum and Search --> : Trapping No Records


Anon
06-14-2001, 03:00 AM
I have a query that selects records from a DB and then loops through the records and checks certain Values, I am looking to see how I can produce a No Records error if the are no records when the query is run.

Here is my code:

$sql = "SELECT * from users where username like '$portaluser'
";
#execute the query
$result = mysql_query($sql)
or die("Error!");

while ($row = mysql_fetch_array($result)) {
$dbsession = $row['currentsession'];
$portallevel = $row['level'];
if ($dbsession == $PHPSESSID){
$message = "All okay";
} else {
header("Location: http://LOCATION GOES HERE");
}
}

It seems quite simple but I have been looking for the answer, many thanks inadvance

vincente
06-14-2001, 07:27 AM
Manuals are your friends, read them.

if (mysql_num_rows($result)==0)
{
echo "Query returned no records";
};