I’m building a php news section – how do you categorise date with the same date (please read details)?

Question by rowan.ashe: I’m building a php news section – how do you categorise date with the same date (please read details)?
In my news section I list 25 most recent news articles from a mysql database. Each article is listed with the most recent at the top descending down the list. Each one starts with the date with a line beneath that and the news title as a url below that. What I’m trying to find out is if two or more articles have the same date, how do I get it to appear under the same date. Should I use an array of some kind?

Best answer:

Answer by Web Design Midlands
You could issue an sql statement and order by ‘columnname’ asc

eg (replace column_name with you date column name)

$ mysqlvariable =”SELECT “column_name”
FROM “table_name”
[WHERE “condition”]
ORDER BY “column_name” [ASC, DESC]”;

$ result = mysql_query($ mysqlvariable);

echo (mysql_fetch_array($ result));

Haven’t checked if it works but something along these line

Regards
Web Design Midlands

http://www.webdesign-midlands.co.uk

Give your answer to this question below!

Revisions

There are no revisions for this post.

Tags: , , , , , , , ,

One Response to “I’m building a php news section – how do you categorise date with the same date (please read details)?”

  1. Vladimir Kornea January 22, 2011 at 7:20 AM #

    While looping through article records, compare date of current article to date of previous article and print new date section if article dates are different. In the first iteration there is no previous article to compare dates with, but since the same action should be taken on the first iteration as on subsequent iterations (printing a date section), it’s enough to initialize the “previous article date” to a value that will cause a mismatch with the “current article date” of the first iteration.

    $ previous_article_date = null;
    foreach( $ articles as $ current_article ) {
        if( $ previous_article_date != $ current_article[‘date’] ) {
            new_day( $ current_article[‘date’] );
        }
        print_article( $ current_article );
        $ previous_article_date = $ current_article[‘date’];
    }

Leave a Reply