SitePoint Sponsor

User Tag List

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

    Last record of the table

    Is there any way to call the last record of a table? Something like EOF or so. I need to pull the three most recent records to display them on a page. Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Ann Arbor, MI
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the easiest thing to do in this case would be:

    mysql_query("select * from your_table order by ID desc limit 3")

    Where ID is whatever column in your table is auto-incrementing, or if you wanted to pull by date, then the date field. Preferably, and to make this faster, the column you order by should be the index key.

    LL

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

    Let me explain better...

    The case is I don't want to pull the three values in the same table, I want to set the three results as a newspaper layout.

    Like this:


    _________________ ________________
    |.........................||........................|
    |.........................||........................|
    |.........................||........................|
    | News = last id.....|| News = last - 1 |
    |.........................||........................|
    |.........................||........................|
    |_______________ ||_______________|
    |.........................||........................|
    |.........................||........................|
    |.........................||........................|
    | News = last - 2 ..||........................|
    |.........................||........................|
    |.........................||........................|
    |________________||_______________|

    Do you copy me?

  4. #4
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u will need to add a date filed to your date field to it, and then order the results by it

  5. #5
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Oh yes?

    And how am I supposed to do that?

  6. #6
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand this correctly, you only need to be able to display the three records in separate tables in the output HTML - you're not actually querying them from separate tables...right?

    In which case, the first code given would work just fine - you just have to play with the output code to make the display function correctly. I wouldn't recommend pulling an odd number of records if you're trying to lay them out horizontally, though - having an empty data cell trailing could royally screw up your layout preferences...

    Mandi
    Love ya - mean it!

  7. #7
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    select * from table order by date DESC limit 0,3

  8. #8
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Right!

    Could you give a sneak preview of the output code?
    I posted a related question and I included the code I thought would do the trick, but it returns an error. Would you mind giving a little peak at it, wouldn't you? Thanks Mandi

  9. #9
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    To slightlywhacked

    And what if the three records have the same date? Does the database have an internal clock to sort which one of the same day posts was the first one? That makes me think I should use the ID in the SELECT statement, too. Or am I wrong?

  10. #10
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Maybe...

    if you check the URL, you'll understand what I need to do:

    http://www.rcmtelevision.com/rcmtelevision.html

    The three news shown above (where the picture is), need to be from local news category (CID=1) and the two news shown below the blue line must come from the international news category (CID=2). The text of the news is Text.News and the title is Title.News. The page must show the most recent records from both categories ALWAYS. Any questions welcome. Please help! I'm on the edge of a nervous breakdown!

  11. #11
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are not actualy putting in the date..
    get a variable
    $x
    asign it the result from the function time()

    $x=time();
    now insert x into your date collum.... its all good unless articles were entered in on the EXACT same second.. now just sort by the date collum like I said before, and pull the first 3 articles..(thats what that limit thing did)

    which code are u asking for? the code to get the date and insert it? or to pull the apporiate articles?

  12. #12
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The code to pull the articles

    I think I can solve this with a little advice.

  13. #13
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are u doing all of this with one table?

  14. #14
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No, three tables

    One is called News and contains [ID, Title, Text, Date, AID(author id), CID (category id)]
    The second one is Authors and contains (ID, Name, Email).
    The third one is Categories and contains (ID, Name).

    Is my database structure wrong? I can submit news to my tables, modify them, even display them all in a different page, I just don't know exactly how to pull the latest records from each category.

  15. #15
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will get u the latest article in the "local category"
    PHP Code:
    select from NewsAuthorsCategories WHERE  News.AID=Authors.ID AND News.CID=Categories.ID AND News.Cid=1 ORDER BY Date LIMIT 0,

    This will get u the latest article in the "international category"
    PHP Code:
    select from NewsAuthorsCategories WHERE  News.AID=Authors.ID AND News.CID=Categories.ID AND News.Cid=2 ORDER BY Date LIMIT 0,

  16. #16
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    THANKS!!!

    Do I still need the time field?

  17. #17
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, just put the value of time() in hte date field


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
  •