L Posted December 2, 2007 Share Posted December 2, 2007 Hey, I'm trying to create a search where a user types a keyword and it searches through the `posts` database...when it finds some matches it echos them.. so I did this: <? if (isset($_POST['search'])) { $key = trim(mysql_real_escape_string(addslashes(strip_tags($_POST['key'])))); $result = mysql_query("SELECT * FROM `posts` WHERE `post`='$key'", $conn1); while ($results = mysql_fetch_array($result)) { $threadinfo = mysql_fetch_array(mysql_query("SELECT * FROM `threads` WHERE `id`='".$results['threadid']."' ORDER BY `timestamp`")); echo "<table><tr class=\"infor\"><td>Thread Name</td><td>Started By</td><td>Date Posted</td></tr><tr><td>".$threadinfo['name']."</td><td>".$results['post']."</td><td>".$results['by']."</td><td>".$results['date']."</td></tr>"; } } but when I click the button nothing happens...can someone tell me what's wrong, or if I just need to approach this another way because no single post will be the keyword...how do I make it so it'll choose the post if the keyword is used in it? thanks EDIT: code fixed up a bit Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 Use LIKE in your query, so give this a try <?php if (isset($_POST['search'])) { $key = trim(mysql_real_escape_string(addslashes(strip_tags($_POST['key'])))); $results = mysql_query("SELECT * FROM `posts` WHERE `post` LIKE '%$key%'", $conn1); while ($threadinfo = mysql_fetch_array($results)) { echo "<table><tr class=\"infor\"><td>Thread Name</td><td>Started By</td><td>Date Posted</td></tr><tr><td>" .$threadinfo['name']."</td><td>".$results['post']."</td><td>".$results['by']."</td><td>".$results['date'] ."</td></tr>"; } } ?> Quote Link to comment Share on other sites More sharing options...
L Posted December 2, 2007 Author Share Posted December 2, 2007 Haha, awesome! Thanks a lot...you always seem to help my problems get resolved so quickly ;D Thanks again, Solved 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.