mysql query error ...

Discussion in 'Databases' started by pepe_lepew1962, Sep 18, 2011.

  1. #1
    Hello:

    I am having a problem fixing/understanding a recent error message. Basically, I have a search form that after validation and filtering stores the variable into a session. Another page/file opens and loads that search field. Everything has always worked but I recently added pagination and suddenly this program no longer works. Any assistance would greatly be appreciated.


    php version=5.3.1
    mysql version=5.1.41


    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 'ASC LIMIT 0,10' at line 1


    Pagination:
    http://www.catchmyfame.com/2007/07/28/finally-the-simple-pagination-class/



    Here is the shortened version of the code:


    include('../pagination/paginator.php');
    $searcher = $_SESSION['sessearchcode'];

    $query = "SELECT COUNT(*) FROM tblLoad, tblCode WHERE (tblLoad_LoadID = tblCode_CodeID) AND tblCode_Manufact LIKE '%$searcher%'";
    $result = mysql_query($query) or die(mysql_error());
    $num_rows = mysql_fetch_row($result);

    $pages = new Paginator;
    $pages->items_total = $num_rows[0];
    $pages->mid_range = 9; // Number of pages to display. Must be odd and > 3
    $pages->paginate();

    $query = "SELECT tblLoad_LoadID, tblLoad_Company, tblLoad_State, tblCode_CodeID from tblLoad, tblCode WHERE (tblLoad_LoadID = tblCode_CodeID) AND tblCode_Manufact LIKE '%$searcher%' ASC $pages->limit";
    $result = mysql_query($query) or die(mysql_error());


    Thank You.
     
    pepe_lepew1962, Sep 18, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    If you're not using a debugger, try
    
    $query = "SELECT tblLoad_LoadID, tblLoad_Company, tblLoad_State,  tblCode_CodeID from tblLoad, tblCode WHERE (tblLoad_LoadID =  tblCode_CodeID) AND tblCode_Manufact LIKE '%$searcher%' ASC  $pages->limit";
    echo $query;
    exit;
    
    PHP:
    to see what you're asct8ually asking MySQL to do.

    Are you sure you didn't mean
    
    $query = "SELECT tblLoad.LoadID, tblLoad.Company, tblLoad.State,  tblCode.CodeID from tblLoad, tblCode WHERE (tblLoad.LoadID =  tblCode.CodeID) AND tblCode.Manufact LIKE '%$searcher%' ASC  $pages->limit";
    
    PHP:
     
    Rukbat, Sep 18, 2011 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    What is "ASC" doing in query without "ORDER BY" clause?

    That's the wrong part. Remove it, or add ORDER BY clause and then check.
     
    mastermunj, Sep 19, 2011 IP
  4. pepe_lepew1962

    pepe_lepew1962 Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Yup, missing was the order by.
    Thanks !!!
     
    pepe_lepew1962, Sep 21, 2011 IP
  5. Mohammed Ammar

    Mohammed Ammar Member

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Please check you order and use order by clause
     
    Mohammed Ammar, Oct 5, 2011 IP