gray8110 Posted January 14, 2009 Share Posted January 14, 2009 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 Link to comment https://forums.phpfreaks.com/topic/140869-solved-testing-if-while-loop-has-no-results/ Share on other sites More sharing options...
gevans Posted January 14, 2009 Share Posted January 14, 2009 Why don't you use your query to filter this data? Link to comment https://forums.phpfreaks.com/topic/140869-solved-testing-if-while-loop-has-no-results/#findComment-737338 Share on other sites More sharing options...
gray8110 Posted January 15, 2009 Author Share Posted January 15, 2009 Thanks... that solved my problem I tried using the query to filter results initially, but was only getting a partial result. I must have had some bad syntax in the query at that point because it works beautifully now. Link to comment https://forums.phpfreaks.com/topic/140869-solved-testing-if-while-loop-has-no-results/#findComment-737386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.