How would i make a search bar?

Discussion in 'Programming' started by Kurt Whittingham, Mar 26, 2012.

  1. #1
    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
     
    Kurt Whittingham, Mar 26, 2012 IP
  2. yester123

    yester123 Peon

    Messages:
    360
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    on which platform are you creating your site????
     
    yester123, Mar 26, 2012 IP
  3. allricjohnson

    allricjohnson Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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>
     
    allricjohnson, Mar 26, 2012 IP
  4. kids

    kids Active Member

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    68
    #4
    You should try with Google Custom Search.
     
    kids, Mar 26, 2012 IP
  5. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #5
    Google search, isnt what i am looking for..

    I want the search bar to search my website, and my site only.
     
    Kurt Whittingham, Mar 26, 2012 IP
  6. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #6
    im using html, css, php... if thats what you meant
     
    Kurt Whittingham, Mar 26, 2012 IP
  7. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #7
    How are your articles stored?
     
    Arttu, Mar 27, 2012 IP
  8. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #8
    im using mysql database
     
    Kurt Whittingham, Mar 27, 2012 IP
  9. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #9
    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):
     
    Arttu, Mar 27, 2012 IP
  10. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #10
    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
     
    Kurt Whittingham, Mar 27, 2012 IP
  11. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #11
    Your query is invalid.
     
    Arttu, Mar 28, 2012 IP
  12. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #12
    i have multiple tables in my database, so i put categ to get all the tables.... is there a proper way to do this
     
    Kurt Whittingham, Mar 28, 2012 IP
  13. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #13
    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%'".
     
    Arttu, Mar 29, 2012 IP
  14. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #14
    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:
     
    Kurt Whittingham, Apr 2, 2012 IP
  15. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #15
    Your query is still invalid.
     
    Arttu, Apr 2, 2012 IP
  16. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #16
    How would i fix it?
     
    Kurt Whittingham, Apr 4, 2012 IP