SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I limit the display of MySQL fields usings PHP?

    I have a table with 400 plus different items. I only want to display the details of 20 specific items in the 'name' field. I always get all 400 + displayed.

  2. #2
    SitePoint Addict chiefmonkey's Avatar
    Join Date
    Aug 2002
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How do I limit the display of MySQL fields usings PHP?

    Originally posted by Jump
    I have a table with 400 plus different items. I only want to display the details of 20 specific items in the 'name' field. I always get all 400 + displayed.

    you could use LIMIT

    select * from table_name ORDER by name LIMIT 20

    HTH

    George

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Indeed. The LIMIT clause is one of the really useful features of mySQL - it makes "recordset paging" very easy to achieve; far easier than rs.PageSize etc. in ASP.

    From the mySQL docs at http://www.mysql.com/doc/en/SELECT.html ...

    The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments. The arguments must be integer constants. If two arguments are given, the first specifies the offset of the first row to return, the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

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

    If one argument is given, it indicates the maximum number of rows to return:

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

    Have fun!
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have 400 + named items in the 'name' field. I need to use a specific 20 items and they are not necesarily grouped together.Is there anyway I can just call a the specified items?

  5. #5
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or maybe I am looking at this wrong. Maybe its not a matter of calling them, but how do I limit displaying them on the page.

  6. #6
    SitePoint Enthusiast ericthehalfbee's Avatar
    Join Date
    Oct 2001
    Location
    Auckland, NZ
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Limiting the display is explained by the previous posters.

    Hopefully there is some unique and common factor which your 20 records posses and which you can use as the WHERE part of your SQL statement

    SELECT * FROM table WHERE somefield=something

    Is this what youmean??

  7. #7
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I made a new table in the db that only containes what I need and added it to the cronfile that gathers the data for the original table and that seems much easier.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •