date display problem in php...........

Discussion in 'PHP' started by malluwood, Nov 17, 2006.

  1. #1
    hi all


    I am new to php. I have a problem in my site.I have a news and Events section in my home page,in which i want to display the latest news and events based on current server date.I am storing entire date in the database.

    database structure

    Input to Mysql database

    DATE(dd-mm-yyyy) News and EVENTS
    8-10-2005 XXXXXXXXXX
    8-10-2006 XXXXXXXXXX
    1-11-2006 XXXXXXXXXX
    14-11-2006 XXXXXXXXXX
    16-11-2006 XXXXXXXXXX
    18-11-2006 XXXXXXXXXX
    30-12-2006 XXXXXXXXXX

    #########################################################
    I need the o/p in the following format(consider 16-11-2006 is the current Server date)

    DATE(dd-mm-yyyy) News and EVENTS
    16-11-2006 XXXXXXXXXX
    18-11-2006 XXXXXXXXXX
    30-12-2006 XXXXXXXXXX
    14-11-2006 XXXXXXXXXX
    01-11-2006 XXXXXXXXXX
    8-10-2006 XXXXXXXXXX
    8-10-2005 XXXXXXXXXX


    could u please use this link
    http://www.gbcmumbai.com/gbcfocus.php

    I want the o/p as

    17-12-2006
    14-11-2006
    13-11-2006
    13-11-2006

    Suppoose I am giving 18-11-2006 it should come as

    18-11-2006
    17-12-2006
    14-11-2006
    13-11-2006
    13-11-2006

    Suppoose I am giving 2day's date as 17-11-2006 and it should come as

    17-11-2006
    18-11-2006
    17-12-2006
    14-11-2006
    13-11-2006
    13-11-2006
    Suppoose I am giving 1-1-2007 and the present date is 17-11-2006,the o/p should be

    17-11-2006
    18-11-2006
    17-12-2006
    1-1-2007
    14-11-2006
    13-11-2006
    13-11-2006

    so when 1-1-2007 comes I want the o/p as

    1-1-2007
    17-12-2006
    18-11-2006
    17-11-2006
    14-11-2006
    13-11-2006
    13-11-2006
    please help me i am not geeting how to achieve
    Thanks and regards
    ANTC
     
    malluwood, Nov 17, 2006 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    
    SELECT
    	(UNIX_TIMESTAMP(CURRENT_DATE()) - UNIX_TIMESTAMP(news_date) - 1) * SIGN(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(news_date) - 1) AS result_diff,
    	SIGN(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(news_date) - 1) AS result_sign,
    	news_date,
    	news_content
    FROM
    	news
    ORDER BY
    	result_sign, result_diff
    
    Code (markup):
     
    SoKickIt, Nov 17, 2006 IP