suckerr70 Posted December 28, 2007 Share Posted December 28, 2007 I have made a posting script in php that works with mysql. I have a few pages that calls for posts depending on the category. If you click the food category link, it will only show stuff from posts with food as the category. Now, I would also like people to be able to search my database for posts and display them. How would I go about doing that? I don't even know where to start. Thanks. Link to comment https://forums.phpfreaks.com/topic/83428-php-search-mysql-database/ Share on other sites More sharing options...
drummer101 Posted December 28, 2007 Share Posted December 28, 2007 <? echo "<a href=\"page.php?food=apples\">"; ?> <? $item = $_GET['food']; $sql = mysql_query(SELECT * FROM your_table WHERE your_table.food = '$item'"); while ($r = mysql_fetch_array($sql)){ echo $r['food_item']; } ?> Link to comment https://forums.phpfreaks.com/topic/83428-php-search-mysql-database/#findComment-424445 Share on other sites More sharing options...
suckerr70 Posted December 28, 2007 Author Share Posted December 28, 2007 I don't really get that script. Can you explain it please? Also, I need the search to search multiple thing like: title, catagory, description. Link to comment https://forums.phpfreaks.com/topic/83428-php-search-mysql-database/#findComment-424480 Share on other sites More sharing options...
drummer101 Posted December 29, 2007 Share Posted December 29, 2007 <? echo "<form name=\"search\" method=\"post\">"; echo "<select name=\"search_by\">"; echo "<option value=\"title\">Title</option>"; echo "<option value=\"category\">Category</option>"; echo "<option value=\"description\">Description</option>"; echo "</select>"; echo "<input type=\"text\" name=\"search\">"; @$search_by = $_POST['search_by']; @$search = $_POST['search']; $sql = mysql_query("SELECT * FROM <your table> WHERE $seach_by LIKE %'$seach'%"); ?> Link to comment https://forums.phpfreaks.com/topic/83428-php-search-mysql-database/#findComment-425161 Share on other sites More sharing options...
Northern Flame Posted December 29, 2007 Share Posted December 29, 2007 here are 2 examples of how to create a search script, the one I posted is a bot more complex, and the one posted by the other person is more simple: http://www.phpfreaks.com/forums/index.php/topic,174411.msg771490.html Link to comment https://forums.phpfreaks.com/topic/83428-php-search-mysql-database/#findComment-425163 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.