SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 42
  1. #1
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date display in php

    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



    please help me the logic or providing the code >

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    if you are inputting values like 8-10-2005 into mysql, then you aren't doing it right, because the only way that works is with a VARCHAR column

    use a DATE column instead

    then you can pull the dates out of mysql in any format you wish -- see the DATE_FORMAT function

    more importantly, you can sort by dates correctly
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry date display

    hai

    Thanks for ur reply

    I am not looking for sorting i e Ascending and descending.I want the o/p as shown in the question.that is based on the current server date it should change
    automatically.I think u got my question.I am in deep trouble

    Thanks

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    no, eye did not get your question
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast peteoc's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT whatever FROM news_table WHERE news_date = 'date'

    go read up a news tutorial in php, google will bring up many and they are very easy to understand.
    www.totaltxt.co.uk - UK Unique Auction Site
    All advise given by myself is used at the risk of the user.
    I will take no responsibility for your databases
    being lost etc.

  6. #6
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date display in php

    hi

    Could u please check the eg:which i have given.I want that format.

    ANIL

  7. #7
    SitePoint Enthusiast peteoc's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about you go away and try doing it yourself, then when you become stuck as its not outputting the correct data, then we can help you.

    What you are asking would result in me charging you for my services as i'd be writing it for you.
    www.totaltxt.co.uk - UK Unique Auction Site
    All advise given by myself is used at the risk of the user.
    I will take no responsibility for your databases
    being lost etc.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    when you say "format" do you really mean "format" or do you mean "sequence"????

    the format looks unchanged

    the sequence looks different, but there is no logic to it

    by the way, what datatype is your date column?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry

    Hi

    Thanx for ur reply

    I need the sequence order.

    The datatype is date format



    ANIL

  10. #10
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    okay, DATE datatype

    can you describe in words what is the sequence you want?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  11. #11
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry

    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
    Last edited by aniltc; Nov 17, 2006 at 02:40.

  12. #12
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no rhyme or reason to the ordering you have provided, at least none that any of us can see. Please describe in words how you want the output to be ordered as the examples obviously are not relaying to us the information we need in order to help you. Repeating examples that we're obviously not understanding is going to help no one and only serve to frustrate all of us.

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    As far as I can see, the only way you are going to be able to get that sort of ordering is by adding a column to your database table with a display order figure.

    Code:
    order || date
      1    || 17-11-2006
      3    || 18-11-2006
      5    || 17-12-2006
      2    || 14-11-2006
      4    || 13-11-2006
      6    || 13-11-2006
    That way you can order by that column and control the output.

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i am not geeting.here the table is dynamic .it's changing frequently.


    Thanks
    ATC

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    ahhhh, so you want to output the list with TODAYS date as the first item out of the list...?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #16
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    hi,
    atleast u got my question. thanks a lot.
    ya i want to output the list with TODAYS date as the first item out of the list.
    and the forthcoming date should be listed below. suppose if the todays date is not available in the database then it should display the latest date record as the first item.

    i think now u might have be more clear about my question.

    i am expecting the logic from u as early as possible

    Thankd and Regards
    Anil T.C
    Bangalore
    Last edited by aniltc; Nov 18, 2006 at 04:33.

  17. #17
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by aniltc
    ya i want to output the list with TODAYS date as the first item out of the list.
    and the forthcoming date should be listed below.
    if you look at all of your examples in this thread, it is pretty easy to see that the sorted list starts with today's event

    and any events in the future are listed next

    HOWEVER, the order is all mixed up, and there are also events from the past mixed in with them!!

    i am expecting an explanation from you at your earliest opportunity!!
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  18. #18
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post date display

    I think 'aniltc' wants 2days date first if they are entering 2day.Tommorow ,they want next latest day. So the latest date will print in the page.

    suppose 2day's date 17-11-2006.it will come first.tommorow it will automaticaly change to next latest date,It maybe 20-11-2006.if they ar going to enter the next events on 18-11-2006,then 18-11-2006 should come first instead of 20-11-2006.
    then the list will look as

    18-11-2006
    20-11-2006
    17-11-2006
    This is what I undersood.This is really a good thread

    Wood

  19. #19
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    wood, i believe from all the examples given in this thread, it is pretty clear that today's news/event must come first

    2 questions: 1) what else comes after that, and 2) in what sequence

    you will notice that there is no logic to the sequence after the first entry

    anil, if all you want is today's event to come first and you don't care about the sequence of any dates that come after, then this will do it for you --
    Code:
    ORDER BY CASE WHEN datefield = CURRENT_DATE THEN 0 ELSE 937 END
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  20. #20
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    wood, i believe from all the examples given in this thread, it is pretty clear that today's news/event must come first

    2 questions: 1) what else comes after that, and 2) in what sequence

    you will notice that there is no logic to the sequence after the first entry

    anil, if all you want is today's event to come first and you don't care about the sequence of any dates that come after, then this will do it for you --
    Code:
    ORDER BY CASE WHEN datefield = CURRENT_DATE THEN 0 ELSE 937 END
    hi r937

    Anyway they want to display 2day's date first if they have provided in the site.Otherwise it should take the next highest date

    After this date the next highest date should come as second,then the 2days date come .I think they are looking for this order.

  21. #21
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date display

    hi all

    ya malluwood you are correct.I am looking for that order.

    I am still trying for this one.is there any problem with my logic ?



    Thanks
    ANIL
    Last edited by aniltc; Nov 18, 2006 at 02:34.

  22. #22
    SitePoint Member Azhagiri's Avatar
    Join Date
    Nov 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Solution to date display

    hi anil and group members,

    from all the discussions above i got what anil is looking for and i found out the solution for it. the code will be little bit to long. i have given the comment line where ever it is needed. hope every one can understand. by seeing this code if any one find solution with minimal code plz discuss with the same heading or if u feel difficult in understanding plz enquire with me.

    **********************************************
    Cod for the date display: (this will help if data type is varchar)
    ***********************************************
    <?php
    $query_Newss = "SELECT id,`date` FROM nande WHERE type=news";
    $Newss = mysql_query($query_Newss, $GBC) or die(mysql_error());
    $row_Newss = mysql_fetch_assoc($Newss);
    $totalRows_Newss = mysql_num_rows($Newss);
    $arrids= array();
    $arrdates= array();
    $mkarrays= array(); //for storing mktime
    $mkarrays1= array(); //for storing mktime, future reference
    $results=array();
    $arrdatees= array();
    $is=0;
    do
    {
    $arrids[$is]=$row_Newss['id'];
    $arrdates[$is]=$row_Newss['date'];
    $is++;
    }while($row_Newss = mysql_fetch_array($Newss));
    //code for splitting the date
    $cnts1=count($arrdates);
    for($is=0;$is<$cnts1;$is++)
    {
    $strings1=$arrdates[$is];
    $arrdatees[$is]=substr($strings1,0,10); // for future reference
    $dds=substr($strings1,0,2); //for date
    $mms=substr($strings1,3,2); //for month
    $yys=substr($strings1,6,4); // for year
    $mkarrays[$is]= mktime(0, 0, 0, $mms, $dds, $yys);
    $mkarrays1[$is]= mktime(0, 0, 0, $mms, $dds, $yys);
    }
    asort($mkarrays);
    $sts=strftime("%m,%d,%Y"); // getting server time
    $sts1= mktime(0, 0, 0, $sts); // getting timestamp for server time
    // code for subtracting server time with the timestamp generated for value stored in database
    for($is=0;$is<$cnts1;$is++)
    {
    $results[$is]=$sts1-$mkarrays1[$is];

    }
    asort($results); //sorting the subtracted value array
    natsort($results); // performing the natuaral sorting algortim for the result array

    // for diaplaying
    $afs=array();
    $afs=array_keys($results);
    $newarrs=array();
    for($is=0;$is<$cnts1;$is++)
    {
    $newarrs[$is]=$results[$afs[$is]];
    }
    // for finding if same date exist in the database
    $zeroarrays=array();
    $kks=0;
    $mms=0;
    $finalarrs=array();
    $indexs=array();
    for($is=0;$is<$cnts1;$is++)
    {
    if($newarrs[$is]==0)
    {
    $zeroarrays[$mms]=$is;
    $mms++;
    }
    }
    $cntzerarrs=count($zeroarrays);
    if($cntzerarrs==0)
    {
    //finalarr will contain the result what we need
    for($is=0;$is<$cnts1;$is++)
    {
    $finalarrs[$is]= date("j-n-Y",($sts1-$newarrs[$is]));

    }

    print_r($finalarrs);
    // for getting the array index value. i.e not having o value
    for($is=0;$is<$cnts1;$is++)
    {
    for($js=0;$js<$cnts1;$js++)
    {
    if($finalarrs[$is]==$arrdatees[$js])
    $indexs[$is]=$arrids[$js];
    }
    }
    } //end of if cntzerarr=0 condition
    else
    {
    for($is=0;$is<$cntzerarrs;$is++)
    {
    $valuess=$zeroarrays[$is];
    $finalarrs[$is]= date("j-n-Y",($sts1-$newarrs[$valuess]));
    $kks=$is;
    }
    for($is=0;$is<$cnts1;$is++)
    {
    if(in_array($is,$zeroarrays))
    {

    }
    else
    {
    $kks=$kks+1;
    $finalarrs[$kks]= date("j-n-Y",($sts1-$newarrs[$is]));
    }
    }
    for($is=0;$is<$cnts1;$is++)
    {
    for($js=0;$js<$cnts1;$js++)
    {
    if($finalarrs[$is]==$arrdatees[$js])
    $indexs[$is]=$arrids[$js];
    }
    }

    }// end of else

    $lastids=$indexs[0];
    $listings = "SELECT id, news, details, `date`, image, title, type FROM nande WHERE type='news' and id='$lastids'";
    $listings1= mysql_query($listings, $GBC) or die(mysql_error());
    $listings2 = mysql_fetch_assoc($listings1);

    ?>

    see i have display only the latest date in lastids. if u want the forthcoming date to be displayed then use the loop to select the query and display it.



    hope it will solve the date problem.

    Bye....
    Azhagiri
    India

  23. #23
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow date display

    hai azha


    Thanks a lot,it solved my problem


    ATC

  24. #24
    SitePoint Member Azhagiri's Avatar
    Join Date
    Nov 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Date display problem

    hi anil,
    it is happy to hear from u that it solved ur problem. the code which i have given is very difficult to understand. i think u can reduce it and if so forward to me

    Thanks..



    Azhagiri
    India

  25. #25
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aniltc
    hai azha


    Thanks a lot,it solved my problem


    ATC

    Thank god for that!
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"


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
  •