SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast vworld's Avatar
    Join Date
    Nov 2000
    Location
    West of Colorado Springs
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Everyone,

    I'm new SQL and although I can create a database, update it, insert, select etc....I've come across a challenge that I'm hoping someone can help me with. I've got a daily news table with about 2,700 rows or news items. I would like to give my users the ability to view the items in the table sorted by date, category, and source of news.

    Here's where the I run up against the challenge...I have created a select statement for the table but I it will return too many items! How can I limit the number of items returned from the database? I'm sure there is a simple solution to the problem I just can't seem to find it...

    Thanks in advance for any help.

    V

  2. #2
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple is an understatement

    Say you have the query
    "select * from table"
    you can make it
    "select * from table limit 10"
    That will select the first 10 items in the db.

    Or you may want to select the 8 most recent items (if there is a date column with the timestamp the item was posted)
    "select * from table ORDER BY date DESC LIMIT 8"

    Hope that helps
    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!

  3. #3
    SitePoint Enthusiast vworld's Avatar
    Join Date
    Nov 2000
    Location
    West of Colorado Springs
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANK YOU soooooo Much!

    That really does help and I knew I was just missing something. =-)

    if ($orderby == 'date'):
    $sql = "select * from dailynews ORDER BY date DESC LIMIT 10'";

    Again, thanks a million....

    V

  4. #4
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not a problem, happy to be of assistance
    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!


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
  •