Jump to content

[SOLVED] Testing if while loop has no results


gray8110

Recommended Posts

The while loop shown below is checking for a string within a MySQL field. That string must match the ID of the user - it also matches the $_GET id in the url.

 

while ($row = mysql_fetch_array($result)) {
$timestamp = strtotime($row["date"]);
$date = date('D F d', $timestamp);
$event = $row["event"];
$eventID = $row["ID"];
$definite = $row["definite"];
$maybe = $row["maybe"];
$defTest = strpos($definite, $userID);
$maybTest = strpos($maybe, $userID);

if ($maybTest !== false) {
echo '<p><strong>'.$event . '</strong> | ' .$date.' | Maybe Attending</p>';
}

elseif ($defTest !== false) {
echo '<p><strong>'.$event . '</strong> | ' .$date.' | Definitely Attending</p>';
}

}

 

There are 100+ rows in the table, but not all will contain the relevant string. Currently, when I use a URL query string for the page on an ID with no results, I get a blank page (as I should). I'd like to be able to add some custom messaging when there are no results, but in this case, I don't know how to test for it.

 

Any ideas?

 

Thanks

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.