Sorrow Posted October 27, 2008 Share Posted October 27, 2008 Ok here is what is happening I am doing a search option and when I click no the search button I need to display the results. it is working great but when there is no result that was found I need to echo "No Item was found" Here is the code that I have include 'opendb.php'; $STitle = $_POST[sTitle]; $query = "SELECT * FROM reviews WHERE m_Title like '%$STitle%' ORDER BY m_Title"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row < 1) { echo "<br> No titles found<br><br><a href='http://www.web.com/reveiws1.php'> Back to Reviews</a>"; }else { echo "<a href='/moviereview.php?index={$row['m_index']}'>{$row['m_Title']} </a><br>" ; } } mysql_close($con); Any suggestion on what I am doing wrong please ?? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 close, but you are checking in the wrong place include 'opendb.php'; $STitle = $_POST[sTitle]; $query = "SELECT * FROM reviews WHERE m_Title like '%$STitle%' ORDER BY m_Title"; $result = mysql_query($query); if(mysql_num_rows($result)) { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href='/moviereview.php?index={$row['m_index']}'>{$row['m_Title']} </a><br>" ; } } else { echo "<br> No titles found<br><br><a href='http://www.web.com/reveiws1.php'> Back to Reviews</a>"; } mysql_close($con); Quote Link to comment Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 use the mysql_num_rows function to get the number of rows and use that - like below include 'opendb.php'; $STitle = $_POST[sTitle]; $query = "SELECT * FROM reviews WHERE m_Title like '%$STitle%' ORDER BY m_Title"; $result = mysql_query($query); $numRows = mysql_num_rows($result); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($numRows < 1) { echo "<br> No titles found<br><br><a href='http://www.web.com/reveiws1.php'> Back to Reviews</a>"; }else { echo "<a href='/moviereview.php?index={$row['m_index']}'>{$row['m_Title']} </a><br>" ; } } mysql_close($con); Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 use the mysql_num_rows function to get the number of rows and use that - like below include 'opendb.php'; $STitle = $_POST[sTitle]; $query = "SELECT * FROM reviews WHERE m_Title like '%$STitle%' ORDER BY m_Title"; $result = mysql_query($query); $numRows = mysql_num_rows($result); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($numRows < 1) { echo "<br> No titles found<br><br><a href='http://www.web.com/reveiws1.php'> Back to Reviews</a>"; }else { echo "<a href='/moviereview.php?index={$row['m_index']}'>{$row['m_Title']} </a><br>" ; } } mysql_close($con); ...the IF needs to be OUTSIDE the while, or you will never reach it Quote Link to comment Share on other sites More sharing options...
Sorrow Posted October 27, 2008 Author Share Posted October 27, 2008 Thank you very much it is working 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.