mysql query error ...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pepe_lepew1962
Forum Commoner
Posts: 44
Joined: Thu Nov 20, 2008 10:29 am

mysql query error ...

Post by pepe_lepew1962 »

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/f ... ion-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.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: mysql query error ...

Post by twinedev »

I don't know how this code worked before, but as it says the error it is that it is finding "ASC" where it is not knowing what to do with it because you have it right after your WHERE statement, yet it needs to be part of an ORDER BY statement.

Looks like you just left that out in the second query:

...tblCode_Manufact LIKE '%$searcher%' ORDER BY fieldname ASC $pages->limit";
pepe_lepew1962
Forum Commoner
Posts: 44
Joined: Thu Nov 20, 2008 10:29 am

Re: mysql query error ...

Post by pepe_lepew1962 »

Yup, that the order by was missing. Thanks.
Post Reply