SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Internal Site Search for small website

    I have made a 15 page website for a client and added the customizable google search facility but he wants his own search results and not this google one.

    I only have very basic knowledge of PHP and have been searching for a script for what seems like a lifetime but they are either too complex or outdated.

    As the site is so small and the only search facility needs to be for the items he has for sale (just old second hand stuff, furniture etc) does anyone know of a basic, easy to use script I could use please?

    Sorry I know this has probably been asked lots before but Ive looked everywhere i can and used all the search terms I can think of and am a bit stumped

    thanks

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,078
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Is your website database driven (i.e. is the searchable content stored in a database) or is it static?
    Also, would your client be willing to pay for this additional functionality?

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    4
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If your website is database driven, use something like this quick script I wrote to fetch the name, author, and URL link to ebooks in a virtual library:

    Code:
    <?php
    
    
    $username="yourusername";
    $password="yourpassword";
    $database="yourdatabase";
    
    $title=$_POST['title'];
    $author=$_POST['author'];
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die("Unable to select database!");
    
    $query="SELECT * FROM books_all WHERE Title = '$title' AND Author = '$author' AND url LIKE 'h%'";
    
    $result=mysql_query($query);
    
    $num=mysql_numrows($result);
    
    mysql_close();
    
    if ($num == "")
    
    {
    	echo "No results! <br><p></p><a href=http://www.yoursite.com/blah.html> Go back </a>";
    } 
    
    else 
    
       {
    	
    echo "<h3> Search Results: </h3>";
    
       }
    
    
    $i=0;
    while($i < $num) {
    
    $title=mysql_result($result,$i,"Title");
    $author=mysql_result($result,$i,"Author");
    $url=mysql_result($result,$i,"url");
    
    
    $i++;
    }
    
    ?>

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    @Stone Rain ;

    That script is not really what the OP is looking for:

    1. Any input provided by the user should always be considered unsafe, it should be sanitized.
    2. When sending a query to MySQL, you should use prepared statements (please read up on what SQL Injection is)
    3. The mysql_* extension is out of date and is deprecated as of the current version of PHP and will likely be removed from the next version of PHP.
    4. You close the connection to the database before getting the search results which can never be accessed as there is no connection to the database over which they can be accessed.
    5. There are functions in the mysqli_* and PDO extensions which can be used to get an array containing the entire result set in one hit.
    6. You're only fetching the results did you intend to display (echo) them?
    7. When using any SELECT query, only select the fields that you need.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    4
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I hit "post" before including the disclaimer that the above is just a concept, not something that should be copied and pasted, my apologies.

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2012
    Posts
    139
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you want to REALLY keep it simple, I use the site search from sitelevel.com on two of my websites and it seems to work great. You can see it working here: BestDryingRack.com

    I do need to figure out how to get Google Analytics to record what search terms people enter in the box. So if anybody knows, please share...

    Good luck!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •