Search Function trouble

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashraf02
    New Member
    • Feb 2008
    • 53

    Search Function trouble

    Someone please help! i am writing a code for a search function and everytime i execute the code i get the following error.

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0,10' at line 1

    i have tried to remove the line of code to see wat happens ia search result appears but with errors.

    can someone please help sort this problem. [PHP]<?php
    $get = $_GET['q'];
    $trim = ($get);
    $row_limit = 10;
    if ($trim == "" ) {
    echo "<p>Enter Search</p>";
    exit;
    }

    if (!isset ($get)) {
    echo "<p>Not Valid Search</p>";
    exit;
    }
    $conn = mysql_connect ("localhost","r oot","")
    or die (mysql_error ());
    mysql_select_db ("noble",$co nn) or die (mysql_error()) ;
    $search = "SELECT *
    FROM Clothes
    WHERE Clothes_Brand LIKE \"%$trim%\"
    ORDER BY Clothes_Brand";
    $search_res = mysql_query($se arch);
    if (mysql_num_rows ($search_res) == 0 ) {
    echo "<h1>Search Result</>";
    echo "<p>Sorry, your search: &quot;" .$trim. "&quot; returned zero results</p>";
    echo "<p><a href=\"Noble_Ho mepage.html\">S earch Again?</a></p>";
    }
    if (empty($s)){
    $s=0;
    }
    $search_query .= "LIMIT $s,$row_limit";
    $query_result = mysql_query($se arch_query) or die(mysql_error ());
    echo "<p>You searched for: &quot;" .$get. "&quot;</p>";
    echo "Results";
    $count = 1 + $s;
    while ($srch = mysql_fetch_arr ay($query_resul t)) {
    $title = $srch ['Clothes_Brand'];
    echo "$count.)&nbsp; $title" ;
    $count++ ;
    }
    $current = (($s/$row_limit) + 1);
    if ($s>=1) {
    $previous=($s-$row_limit);
    print "&nbsp;<a href=\"$PHP_SEL F?s=$previous&q =$get\">&lt;&lt ;
    Prev 10</a>&nbsp&nbsp;" ;
    }
    [/PHP]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    The concatenate result of the LIMI clause to the statement is goping to look like[code=sql] ORDER BY Clothes_BrandLI MIT $s,$row_limit[/code]So you need to specify at least one blank in between.

    Ronald

    Comment

    Working...