Jump to content

No Matches Problem


bschultz

Recommended Posts

I'm trying to come up with some code...and need to echo certain things based on which query failed.

 

There are several query's and while loops nested together.

 

I'm trying to use this...

 

<?php
$rs = mysql_query($sql,$dbc);  
if (! $rs) { echo "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often."; }
$matches = 0; 
while ($row = mysql_fetch_assoc($rs))  
{
$matches++; 
//rest of code here...which work when there are matches...
?>

 

With no matches, it isn't echoing anything...instead of "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often."

 

If I echo out $rs, I get RESOURCE ID #6

 

Any ideas?  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/237926-no-matches-problem/
Share on other sites

well it would help if you provided the query you are using also, but I will assume you are using a select statement. With select statements, the result resource that is obtained from doing mysql_query will coerce to true unless there was a mysql error (even if there are no rows returned). You basically want to check if there were any rows returned. You can use mysql_num_rows to check how many rows were returned from your query. for example

$rs = mysql_query($sql,$dbc);  
$num = mysql_num_rows($rs);
if (!$num) { echo "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often."; }
$matches = $num;//no need for a while loop 

Link to comment
https://forums.phpfreaks.com/topic/237926-no-matches-problem/#findComment-1222655
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.