TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   mysql query error ... (http://www.talkphp.com/mysql-databases/5986-mysql-query-error.html)

pepelepew1962 09-18-2011 07:14 PM

mysql query error ...
 
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/2...ination-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.

tony 09-19-2011 02:15 AM

what does $pages->paginate(); do?
I am not sure if maybe it has to do that you are trying to make a select union and selecting the fields by not using the table reference. For example, instead of
sql Code:
SELECT tblLoad_LoadID, tblLoad_Company ...
to
sql Code:
SELECT tbload.tbLoad_LoadID, ..., tblCode.tblCode_CodeID ...
Maybe that is why?

wGEric 09-19-2011 06:48 PM

Get rid of ASC. There is no ORDER clause in your query.

PHP Code:

$query "SELECT tblLoad_LoadID, tblLoad_Company, tblLoad_State, tblCode_CodeID from tblLoad, tblCode WHERE (tblLoad_LoadID = tblCode_CodeID) AND tblCode_Manufact LIKE '%$searcher%' $pages->limit"


pepelepew1962 09-21-2011 07:37 PM

Yeah, I was missing the ORDER BY. Thanks !!!!


All times are GMT. The time now is 04:53 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0