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 Link to comment https://forums.phpfreaks.com/topic/79765-solved-creating-a-search/ 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>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/79765-solved-creating-a-search/#findComment-403941 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 Link to comment https://forums.phpfreaks.com/topic/79765-solved-creating-a-search/#findComment-403943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.