www.webdeveloper.com
Results 1 to 2 of 2

Thread: Changes required to php search function

  1. #1
    Join Date
    Jul 2007
    Posts
    14

    Changes required to php search function

    Hi

    Ive gone and found myself a bit of script that allows me to successfully search my database for all items that relate to what is entered in the search field. just want to be able to change slightly how the results are displayed and the search bit itself slightly

    1. Want it so the user can search in a box that is already been placed on all of my pages
    2. Want the results to be displayed 10 results at a time and the remaining to be displayed on page2


    this is code i am using if anyone can help it would be greatly appreciated:



    <html>
    <head><title>Search</title></head>
    <body>

    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    include ("func.inc");
    connectDB();




    // Create the navigation switch
    $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');

    switch($cmd)
    {
    default:
    echo '<h1>Search</h1>';
    searchForm();

    break;


    case "search":
    searchForm();
    echo '<h3>Search Results:</h3><br />';

    $searchstring = mysql_escape_string($_GET['words']);
    switch($_GET['mode'])
    {
    case "normal":
    $sql = "SELECT ProductName, ProductDescription, Url,
    MATCH(ProductName, ProductDescription, Url)
    AGAINST ('$searchstring') AS score FROM Products
    WHERE MATCH(ProductName, ProductDescription, Url)
    AGAINST ('$searchstring') ORDER BY score DESC";
    break;

    case "boolean":
    $sql = "SELECT ProductName, ProductDescription, Url,
    MATCH(ProductName, ProductDescription, Url)
    AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM Products
    WHERE MATCH(ProductName, ProductDescription, Url)
    AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
    break;
    }


    // echo $sql;

    $result = mysql_query($sql) or die (mysql_error());

    while($row = mysql_fetch_object($result))
    {
    echo '<strong>product: <a href="http://www.thedigitaloutlet.co.uk/products/'.stripslashes(htmlspecialchars($row->Url)).'">'.stripslashes(htmlspecialchars($row->ProductName)).'</a></strong><br />';
    echo 'date: '.date('m/d/y', $row->Products_dts).'<br />';
    echo '<p>product description: '.stripslashes(htmlspecialchars($row->ProductDescription)).'</p>';
    echo '<hr size="1" />';
    }
    break;
    }
    ?>

    </body>
    </html>
    Last edited by sh4uk4t; 08-08-2007 at 04:20 AM.

  2. #2
    Join Date
    Jul 2007
    Posts
    357
    LIMIT 0,10 - this would give you the first pages
    LIMIT 10,10 - 2nd page.. and so on.. Do a search pagination.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles