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? Quote Link to comment 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] Quote Link to comment 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! :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.