We help IT Professionals succeed at work.

MySQL Linit

mhoggatt1
mhoggatt1 asked
on
Medium Priority
225 Views
Last Modified: 2010-08-05
How can I add a limit of 10 to this statement -

$sql1 = "SELECT path,playcount from jz_nodes WHERE playcount > '0' and path LIKE '%{$nameArray[$r]}%' and ptype = 'track' order by path asc";
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Like so:

$sql1 = "SELECT path,playcount from jz_nodes WHERE playcount > '0' and path LIKE '%{$nameArray[$r]}%' and ptype = 'track' order by path asc LIMIT 10";

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Commented:
More info on MySQL LIMIT, from MySQL.com:

"The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

With one argument, the value specifies the number of rows to return from the beginning of the result set:

SELECT * FROM tbl LIMIT 5;     # Retrieve first 5 rows

In other words, LIMIT row_count is equivalent to LIMIT 0, row_count. "

Other helpful SELECT syntax examples here:
http://dev.mysql.com/doc/refman/5.0/en/select.html
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.