me1000 Posted March 9, 2006 Share Posted March 9, 2006 ok Im using a simple search script that I wrote but when there was no results returning It shows up blank and I want to change that. heres my script[code]while($r=mysql_fetch_array($result)){ // change page type #'s to words$page_type = $r["PAGE_TYPE"];$new_type = "";if ($page_type == 1) {$new_type = "Home";} else if ($page_type == 2) {$new_type = "Series";} else if ($page_type == 3) {$new_type = "Movies";} else if ($page_type == 4) {$new_type = "Special Features";} else if ($page_type == 5) {$new_type = "Gaming";} else {$new_type = "Unknown";} //modify these to match your mysql table columns $title=$r["PAGE_TITLE"]; $message=$r["PAGE_CONTENT"]; $id=$r["ID"]; $link = '<a href ="index.php?page_id='.$id.'">'.$new_type.': '.$title.'</a>'; $text_output = strip_tags($message, ''); $search_results = substr($text_output, 0, 200); //display the data echo "$link <br> $search_results ... <br><hr>"; }[/code]Im thinking I would need something like if ($r < 1) { $show_results2 }else { echo "$link <br> $search_results ... <br><hr>";}will this work? Link to comment https://forums.phpfreaks.com/topic/4495-no-results-when-search/ Share on other sites More sharing options...
Barand Posted March 9, 2006 Share Posted March 9, 2006 A couple of ways to do this1.[code]$result = mysql_query (" SELECT blah ...... "); // get count of rows returned by queryif (mysql_num_rows($result) > 0) { while ($r = mysql_fetch_array($result)) { // output row data }}else { echo "No records found";}[/code]2.[code]$result = mysql_query (" SELECT blah ...... "); // try to get first rowif ($r = mysql_fetch_array($result)) { do { // output row data } while ($r = mysql_fetch_array($result));}else { echo "No records found";}[/code] Link to comment https://forums.phpfreaks.com/topic/4495-no-results-when-search/#findComment-15912 Share on other sites More sharing options...
me1000 Posted March 11, 2006 Author Share Posted March 11, 2006 Thanks, so I had the right idea just a little off in the sintax! :) Link to comment https://forums.phpfreaks.com/topic/4495-no-results-when-search/#findComment-16265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.