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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.