blodlesme Posted February 9, 2009 Share Posted February 9, 2009 Hi guys , i am a newbie and i don't know much php , I'm folowing tutorials. I want to make a search for my site and i read every tutorial that was on the net and i still don't get it. I have 5 values in my dbase , id , name , name_2,value and pic_url , now i just want to search name and name_2 and then echo results, id value and pic_url.Can some one guide me trough that? Link to comment https://forums.phpfreaks.com/topic/144440-i-need-help-with-making-search-for-my-page/ Share on other sites More sharing options...
ratcateme Posted February 9, 2009 Share Posted February 9, 2009 can you do mysql queries? if not read up on how to do and display a mysql query here http://www.tizag.com/ now for the search you can use a query like $query = "SELECT * FROM `table` WHERE `name` LIKE(\"%$search%\") OR `name_2` LIKE(\"%$search%\")"; Scott. Link to comment https://forums.phpfreaks.com/topic/144440-i-need-help-with-making-search-for-my-page/#findComment-757929 Share on other sites More sharing options...
blodlesme Posted February 9, 2009 Author Share Posted February 9, 2009 yeah i get that , but how will the search form look like , i mean where does this goes %$search%? Link to comment https://forums.phpfreaks.com/topic/144440-i-need-help-with-making-search-for-my-page/#findComment-757951 Share on other sites More sharing options...
ratcateme Posted February 9, 2009 Share Posted February 9, 2009 here is a basic search with very basic stuff and should be protected ageist all SQL injections <?php include "dbConnect.php"; if(isset($_GET['search'])){ $search = mysql_real_escape_string($_GET['search']); $query = "SELECT * FROM `table` WHERE `name` LIKE(\"%$search%\") OR `name_2` LIKE(\"%$search%\")"; $result = mysql_query($query) or die(mysql_error() . "<br>" . $query); if(mysql_num_rows($result) == 0){ echo "No results returned"; }else{ echo "<table>"; while($row = mysql_fetch_assoc($result)){ echo "<tr><td>{$row['id']}</td><td>{$row['value']}</td><td>{$row['pic_url']}</td></tr>"; } echo "</table>"; } } ?> <form method=get> <input type="text" name="search" value="<?=$_GET['search']?>" /><input type="submit" value="Search" /> </form> it would proberly need some work but it shows a basic search function Link to comment https://forums.phpfreaks.com/topic/144440-i-need-help-with-making-search-for-my-page/#findComment-757956 Share on other sites More sharing options...
blodlesme Posted February 9, 2009 Author Share Posted February 9, 2009 Thank you very much ratcateme , it's all i needed , it works perfectly!! Thanks again. Link to comment https://forums.phpfreaks.com/topic/144440-i-need-help-with-making-search-for-my-page/#findComment-758009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.