lukelee Posted September 17, 2008 Share Posted September 17, 2008 this is the search function, when couldnt find anything, "Sorry, but we can not find an entry to match your query" this msg will jump out, otherwise, just show the result. my problem is whatever find or not, this msg will always show up. can anyone help? here is my code: <? if ($searching =="yes") { echo "<h2>Results</h2><p>"; if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } require_once('db.php'); $data = mysql_query("SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$_POST[find]%' OR author LIKE '%$_POST[find]%' OR keyword LIKE '%$_POST[find]%'"); ?> <table border='1'width='500'> <tr> <td>Book Id</td> <td>Book Title</td> <td>Author</td> </tr> <? while($result = mysql_fetch_array( $data )) { echo("<tr>"); echo("<td>$result[book_id]</td>"); echo("<td>$result[book_title]</td>"); echo("<td>$result[author]</td>"); echo("</tr>"); } require_once('rent.php'); ?> </table> <? $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } ?> Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/ Share on other sites More sharing options...
gaza165 Posted September 17, 2008 Share Posted September 17, 2008 <?php $search = $_POST['find']; if ($searching =="yes") { echo "<h2>Results</h2><p>"; if ($search == "") { echo "<p>You forgot to enter a search term"; exit; } require_once('db.php'); $data = mysql_query("SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$search%' OR author LIKE '%$search%' OR keyword LIKE '%$search%'"); ?> <table border='1'width='500'> <tr> <td>Book Id</td> <td>Book Title</td> <td>Author</td> </tr> <?php while($result = mysql_fetch_array( $data )) { echo("<tr>"); echo("<td>$result[book_id]</td>"); echo("<td>$result[book_title]</td>"); echo("<td>$result[author]</td>"); echo("</tr>"); } require_once('rent.php'); ?> </table> <?php $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } ?> try using this code let me know if it works Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/#findComment-643588 Share on other sites More sharing options...
dave_sticky Posted September 17, 2008 Share Posted September 17, 2008 Can you echo out your SQL? <?php $sql = "SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$_POST[find]%' OR author LIKE '%$_POST[find]%' OR keyword LIKE '%$_POST[find]%'"; echo $sql; ?> Also, doesn't mysql_query() need a link identifier as well: <?php $data = mysql_query($sql,$link); ?> Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/#findComment-643589 Share on other sites More sharing options...
gaza165 Posted September 17, 2008 Share Posted September 17, 2008 ahh yes well spotted dave... Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/#findComment-643590 Share on other sites More sharing options...
lukelee Posted September 17, 2008 Author Share Posted September 17, 2008 Can you echo out your SQL? <?php $sql = "SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$_POST[find]%' OR author LIKE '%$_POST[find]%' OR keyword LIKE '%$_POST[find]%'"; echo $sql; ?> Also, doesn't mysql_query() need a link identifier as well: <?php $data = mysql_query($sql,$link); ?> thanks man, i have solved it. Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/#findComment-643595 Share on other sites More sharing options...
lukelee Posted September 17, 2008 Author Share Posted September 17, 2008 hey, by the way, whats different between <? and <?php are they different? seems they all work Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/#findComment-643693 Share on other sites More sharing options...
beansandsausages Posted September 17, 2008 Share Posted September 17, 2008 <? is short term may not be supported by your server, <?php is supported by all sevrers. I think thats correct Link to comment https://forums.phpfreaks.com/topic/124609-can-someone-talk-a-look-at-my-codes-and-tell-me-whats-wrong-with-it/#findComment-643699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.