kjavia795 Posted June 21, 2008 Share Posted June 21, 2008 $query = "SELECT * FROM uploads WHERE title = '".$_POST['textfield']."' ORDER BY title ASC"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { if($_POST['textfield'] == $row['title']) { echo "<a href='index.php?p=view&sub=".$row['id']."'>".$row['title']."</a><br>"; } else if ($_POST['textfield'] != $row['title']) { echo "Search field was not found. Please go back and enter a search item."; } }} Basically, its searching if w/e was entered into a textfield is in the database... and if it is it will be displayed. But when it isn't, it isn't showing the Search field was not found. Please go back and enter a search item. It only shows a blank page. Any help? Quote Link to comment https://forums.phpfreaks.com/topic/111279-little-help/ Share on other sites More sharing options...
.josh Posted June 21, 2008 Share Posted June 21, 2008 first off, you do not need else if ($_POST['textfield'] != $row['title']) { because you do not need to specify the exact opposite of your if statement. All you need is a simple if (...) { } else { } In fact, you don't even need the if statement, since you're asking your database to return results based on the posted value in the first place. As far as your problem is concerned, that message will never echo because the while loop will only execute if it's true in the first place. If you want some kind of "nothing was found" message, you can do something like this: $query = "SELECT * FROM uploads WHERE title = '".$_POST['textfield']."' ORDER BY title ASC"; $result = mysql_query($query); $rows = mysql_num_rows($result); if ($rows > 0) { while($row = mysql_fetch_array($result)) { echo "<a href='index.php?p=view&sub=".$row['id']."'>".$row['title']."</a><br>"; } // end while } else { echo "Search field was not found. Please go back and enter a search item."; } // end else. Quote Link to comment https://forums.phpfreaks.com/topic/111279-little-help/#findComment-571203 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.