Hello. I want to make a search bar for my website. I know i can get one from google, but that searches google etc. I need one that will search the content of my website. What I want to happen is if someone searches "boots" a page will show all the articles that are about boots. How would i do this
Hey hi...try this code. <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <!--webbot bot="Search" S-Index="All" S-Fields S-Text="Search for:" I-Size="20" S-Submit="Start Search" S-Clear="Reset" S-TimestampFormat="%m/%d/%Y" TAG="BODY" --><p> </p> </body> </html>
Google search, isnt what i am looking for.. I want the search bar to search my website, and my site only.
Here's a quick example: <form action="" method="get"> <input type="text" name="kw" /> <input type="submit" value="Search" /> </form> <?php $keyword = $_GET['kw']; if(!empty($keyword)){ mysql_connect("localhost", "username", "password"); mysql_select_db("dbname"); $query = "SELECT * FROM articles WHERE article LIKE '%$keyword%' "; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['title']. "<br />"; } } ?> Code (markup):
this is what i changed the code to <form action="" method="get"> <input type="text" name="kw" /> <input type="submit" value="Search" /> </form> <?php $keyword = $_GET['kw']; if(!empty($keyword)){ require('connect.php'); $query = "SELECT * FROM categ LIKE '%$keyword%' "; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['title']. "<br />"; } } ?> PHP: and this is the error i got Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/motorbik/public_html/test.php on line 47
i have multiple tables in my database, so i put categ to get all the tables.... is there a proper way to do this
If you wanna select data from multiple table you can just do this: "SELECT table1.*, table2.* table3.* FROM table1, table2, table3". Also "LIKE '%$keyword%' " should be "WHERE something LIKE '%$keyword%'".
I am now getting this error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/motorbik/public_html/new 2.php on line 54 This is the code <form action="" method="get"> <input type="text" name="kw" /> <input type="submit" value="Search" /> </form> <?php $keyword = $_GET['kw']; if(!empty($keyword)){ require('connect.php'); $query = "SELECT categ * FROM supercross_race_reviews, how_to, Gear_reviews LIKE WHERE something LIKE '%$keyword%'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['title']. "<br />"; } } ?> PHP: