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

    Join Date
    Jul 2000
    Location
    San Antonio, Texas, USA
    Posts
    23
    Rep Power
    0
    I am creating a News manegment script for my site, I ran into a problem though, on my main page how could I post the five most recent post's titles? I have it set up by $title $content and $relatedartist. How could I do this? Would I have to add a date posted field?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    3
    Rep Power
    0
    Yes you would probably need a date field.

    Then your select statement would look something like this:

    Where table is your table name and date_field is the name of the date submitted

    select * FROM table ORDER BY date_field LIMIT 0, 5

    -Paul

    [This message has been edited by hthighway (edited July 20, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    San Antonio, Texas, USA
    Posts
    23
    Rep Power
    0
    Is there a way to have the date feild change atomatically to what day it is? Do you know of a toturial of how to set up this whole thing?
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    3
    Rep Power
    0
    lets see, to set a variable to the date and time the article was submitted you could do something like this

    $entrydate=gmdate("YmdHis");

    This will return a string of the Year Month Day Time

    On your input form use the $entrydate variable to insert into the date field of your table
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    select * FROM table ORDER BY date_field LIMIT 0, 5


    You have to issue following sql statement for getting last 5 records..(add 'desc' clause in above sql statement)

    select * FROM table ORDER BY date_field DESC LIMIT 0, 5


    -----

    Is there a way to have the date feild change atomatically to what day it is? Do you know of a toturial of how to set up this whole thing?

    see, just add a date field to your current table.when you fetch the last record.use your date field for sorting...

    for adding a new field into your table just try...

    "alter table tablename add dt timestamp(16);"

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

    when you insert a new record...add current time(NOW()) to that datefield..

    "insert into tablename(field1,field2,dt) values('$field1','$field2','NOW()')";

    .............

    finally sort it by dt field..

    select * FROM table ORDER BY dt DESC LIMIT 0, 5;

    that is it!!!


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    err...you should almost always have an id field which auto increments.

    if this is the case u could simply ORDER by id desc LIMIT 5

    Basil
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    San Antonio, Texas, USA
    Posts
    23
    Rep Power
    0
    I'm just starting with this stuff, how do you create auto increments?
  14. #8
  15. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2000
    Location
    Enschede, The Netherlands
    Posts
    1,527
    Rep Power
    16
    Enter the following in MySQL:

    CREATE TABLE tablename (
    id INT(4) NOT NULL AUTO_INCREMENT,
    ....,
    PRIMARY KEY( id )
    );

    Mirax

Similar Threads

  1. Parsing News Feeds
    By jessenco in forum XML Programming
    Replies: 1
    Last Post: January 21st, 2004, 03:13 AM
  2. XML Flash News Ticker
    By jessenco in forum Flash Help
    Replies: 0
    Last Post: January 19th, 2004, 04:23 PM
  3. Parsing News Feeds
    By jessenco in forum HTML Programming
    Replies: 0
    Last Post: January 19th, 2004, 02:54 PM
  4. help with news editor script i made
    By ironmanx in forum PHP Development
    Replies: 3
    Last Post: March 10th, 2003, 11:15 AM
  5. Adding category to simple news script..
    By IanMylett in forum MySQL Help
    Replies: 4
    Last Post: July 2nd, 2002, 10:25 AM

IMN logo majestic logo threadwatch logo seochat tools logo