SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Just a little question

    If I am to pull the three most recent news to a main page in different tables, is this the right way to do it?

    First
    PHP Code:
      $result mysql_query(
                
    "SELECT * FROM News, Authors, Categories WHERE News.AID=Authors.ID AND News.CID=Categories.ID AND News.CID=1 ORDER BY Date DESC LIMIT 0,1"); 
    then
    PHP Code:
      $result mysql_query(
                
    "SELECT * FROM News, Authors, Categories WHERE News.AID=Authors.ID AND News.CID=Categories.ID AND News.CID=1 ORDER BY Date DESC LIMIT 1,1"); 
    and last
    PHP Code:
      $result mysql_query(
                
    "SELECT * FROM News, Authors, Categories WHERE News.AID=Authors.ID AND News.CID=Categories.ID AND News.CID=1 ORDER BY Date DESC LIMIT 2,1"); 
    Please help, thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It could be done more efficiently:

    PHP Code:
    $resmysql_query(
                
    "SELECT count(ID) as Num 
                         FROM News"
    );
    $row mysql_fetch_array($res);


    $limit $row[Num] - 2;

    $result mysql_query(
                
    "SELECT * FROM News, 
                                       Authors, 
                                       Categories 
                               WHERE News.AID=Authors.ID AND
                                         News.CID=Categories.ID AND 
                                         News.CID=1 
                               ORDER BY Date DESC 
                               LIMIT 
    $limit,3");

    while (
    $row mysql_fetch_array($result)) {

    create tables here


    This would get you from 3 select statements to two. You could do it with one this way,

    PHP Code:
    $result mysql_query(
                
    "SELECT * FROM News, 
                                       Authors, 
                                       Categories 
                               WHERE News.AID=Authors.ID AND
                                         News.CID=Categories.ID AND 
                                         News.CID=1 
                               ORDER BY Date ASC 
                               LIMIT 0,3"
    );

    while (
    $row mysql_fetch_array($result)) {

    create tables here


    but the three articles would be listed in ascending order.
    Last edited by Marty H.; Jul 9, 2001 at 10:08.
    Marty H.

  3. #3
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want the most recent use DESC to get descending order which will go from higest to lowest.

    Code:
    ORDER BY Date DESC LIMIT 0,3


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
  •