Results 1 to 6 of 6

Thread: Fetching a certain # of items from MySQL [Resolved]

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Resolved Fetching a certain # of items from MySQL [Resolved]

    Is it possible to do a mySQL query that returns like, say, the 10 more recent results? Or purphaps the 10 highest IDs in a database but can also account for the possibility there may be only 3 or 8?

    Basically I need an easy way to grab the 10 most recent items from a database but also there may not be more than 3 or 8 but there could also be 15.

    What do you recommend?
    Last edited by Kasracer; Jul 25th, 2005 at 01:14 PM.

  2. #2
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Fetching a certain # of items from MySQL

    I don't understand this one much. hmmm.
    is this more of a database problem? like making the query?
    well i think it can be done programatically, u just order the records the most recent goes on top.. and do some fancy codework.

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Fetching a certain # of items from MySQL

    Yeah it's a database thing.

    I know how to fetch everything and then basically break it apart, however; I thought I saw some MySQL LIMIT queries online, I just can't get them to work or figure out how to use them. I figured if I could limit the amount of items returned from a MySQL query, it would be more efficient.

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: Fetching a certain # of items from MySQL

    You need to sort your results in descending order then apply the LIMIT, like this.
    Code:
     SELECT column_1, column_2 FROM table_1 WHERE condition ORDER BY column_to_sort DESC LIMIT 10

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Fetching a certain # of items from MySQL

    Thanks a lot

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Fetching a certain # of items from MySQL [Resolved]

    You will need to add a new column with a timestamp. As there is no gurauntee you will get the records out in the same order it went in.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width