#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Viborg, Denmark
    Posts
    1
    Rep Power
    0
    I have a table called news consistiing of the following fields:
    id datetime primary key
    headline text
    link text

    Whenever someone loads the index page, I would like to show them the 3 latest entries.

    How can I do this?

    Thanks
    Michael
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    I'm not the most qualified to answer this, but I will be using the same "idea" in my pages to come. Maybe someone will come in, correct me, and make us both the wiser.

    First, set query to what you want.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $query="SELECT id FROM tablename ORDER BY id LIMIT 3";
    [/code]
    Then run that query to get your headlines:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $hdln_array=mysql_query($query) or die("Selection Failed!");
    [/code]

    Finally, print out your results:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    while ($headline=mysql_fetch_array($hdln_array)) {
    echo "The date/time : " $headline['id'];
    echo "The Title : " $headline['title'];
    echo "The Link : " $headline['link'];
    [/code]

    Remember to encapsulate your php3 code in <? and ?> brackets.

    Hope that helps a little,

    Mike


    ------------------


    [This message has been edited by mmccue (edited February 28, 2000).]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 1999
    Posts
    2
    Rep Power
    0

    try something like:

    select * from news order by datetime ascending limit 3

  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Quazzy is correct except if you want the newest articles you'd want to use descending.

Similar Threads

  1. order posts by last reply !? how ?
    By toxical in forum MySQL Help
    Replies: 3
    Last Post: February 4th, 2004, 07:43 AM
  2. Replies: 6
    Last Post: January 27th, 2003, 12:16 PM
  3. Calculating the day with most posts...
    By Maverick21 in forum PHP Development
    Replies: 2
    Last Post: January 17th, 2003, 03:28 PM
  4. Keeping track of read posts (forum)
    By SiCo in forum PHP Development
    Replies: 10
    Last Post: March 31st, 2002, 10:00 AM
  5. word play on my forum posts.
    By alligatorTim in forum PHP Development
    Replies: 4
    Last Post: March 7th, 2002, 08:59 PM

IMN logo majestic logo threadwatch logo seochat tools logo