473,500 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using order by and limit gives error

omerbutt
638 Contributor
hi i have written a query and it is giving me th 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 ' 2' at line 6
SELECT * FROM pretzel_products P , pretzel_products_description PD WHERE (P.prod_id=PD.prod_id and prod_status<>'0') ORDER BY prod_date_added DESC LIMIT , 2
here is my query ,
any suggesstions
Expand|Select|Wrap|Line Numbers
  1. $q="SELECT * FROM 
  2.                     ".PRODUCT." P , 
  3.                     ".PRODUCT_DESCRIPTION." PD
  4.                 WHERE     
  5.                     (P.prod_id=PD.prod_id and prod_status<>'0') 
  6.                     ORDER BY prod_date_added DESC AND LIMIT $offset , $limit ";
  7.             $r=execute($q);
  8.  
Dec 5 '09 #1
3 1959
Atli
5,058 Recognized Expert Expert
Hey.

You are missing the offset in your LIMIT clause.
The manual lists it as:
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
Expand|Select|Wrap|Line Numbers
  1. -- Yours is like:
  2. ... LIMIT , 2
  3.  
  4. -- It needs to be either
  5. ... LIMIT 1, 2
  6.  
  7. -- Or just
  8. ... LIMIT 2
  9.  
  10. -- Can also be
  11. ... LIMIT 2 OFFSET 1
Dec 6 '09 #2
kovik
1,044 Recognized Expert Top Contributor
So basically, the error is that your variable, $offset, is empty.

Also, there is an inconsistency between the queries being shown. In your code, you have an "AND" between the ORDER BY clause and the LIMIT clause... That is invalid syntax.
Dec 12 '09 #3
omerbutt
638 Contributor
yeah that AND was a typo mistake and basically the error was that the offset variable was empty
due to which the error was occuring
hanks
regards,
Omer Aslam
Dec 15 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3079
by: Ed | last post by:
------=_NextPart_000_001D_01C34FCC.1D2B5E50 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable There seems to be a significant penalty imposed by the...
10
14022
by: Randell D. | last post by:
Folks, I have a SELECT that returns with multiple records - It works when I have a LIMIT clause but when I try to include a GROUP BY clause, the select returns nothing (ie no records, no...
11
4790
by: Experienced but Undocumented | last post by:
Hi, I have a table with three columns: datetime, subject, & author. (There are more columns, but these are the only relavent ones.) Some rows will have identical subjects. For each subject,...
2
5419
by: Experienced but Undocumented | last post by:
Here's another one; thanks so much to everyone who helped with my last problem. I can't upgrade mySQL but I figured out a way around it from your examples. SELECT `subject` , max( `datetime` )...
1
1659
by: Tom Schindl | last post by:
Hi, the following Statement worked on MySQL 4.0 but after upgrading to 4.1.12 on win32 the order is not working any more. Is this a known problem or is our SQL simply not useable on 4.1 or is...
1
1527
by: Joseph R. Thomas | last post by:
hi, i am utilizing a web service in a C# windows application for a smart client. there is a method public int ValidateUser(string userName, string password) { object results =...
25
2735
by: Mark Harrison | last post by:
I would like to try and build a queuing mechanism on top of Postgresql. Imagine an application where a large number of processes generate images and queue up thumbnail requests. A smaller number...
3
2883
by: dinox | last post by:
hello, i tried searching for something similar to my situation but i haven't found so far.. for example ... i have users table with 15 registered users and i want to show only 5 of them in front...
16
2860
by: canabatz | last post by:
im trying to update my results and i get error: this is the code: this is the select : SELECT * FROM `bidding_details` where `bid_id`='$bid_id' and `sortbid` = '1' order by bid_price asc limit...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.