Jump to content

Sort by current date problem


devain

Recommended Posts

Hello Everyone

 

 

I am hoping someone can help me dont know why but for some reason I am having problems ordering by currentdate..  What I have below is a query that pulles values from the database to be displayed.  in the Fquery are the values the last being startdate.  This value startdate is the event date (with DateTime in the database which is displayed as 4/7/2007 5:00:00 PM) I have no problems sorting by startdate which sorts as follows:

 

Event Date:  Jun 12, 2007 8:00 PM

 

Event Date:  May 31, 2007 8:15 PM

Event Date:  May 24, 2007 6:00 PM

Event Date:  Apr 24, 2007 6:00 PM

and so on starts from furture dates and down

 

What I am wanting to do is show the current date April first then may then June etc.

 

If anyone can help would be appericated thanks

 

 

if (!isset($s) || $s < 1 || !is_numeric($s)) {

            $s = 1;

        }

$time=date("Y-m-d H:m:s");

 

$time_array = explode( ' ', $time );

$time2 = explode("-", $start_array[0]);

 

$day=$time2[2];

$month=$time2[1];

$year=$time2[0];

 

$start = ($s - 1) * $lim;

    $fquery = "select id,title,summary,hits,status,key1,key2,key3,filename,startdate from pr where startdate>='$time'";

 

       

        $countpages = $fquery;

 

        $fquery = $fquery . " order by startdate desc limit $start, $lim";

        $res = mysql_query($fquery);

        $pages = ceil(mysql_num_rows(mysql_query($countpages)) / $lim);

        if ($pages > 1) {

            echo("<p align=left style=\"font-size: 85%\">");

            for ($i = 1; $i <= $pages; $i++) {

               

                if ($i == $s) {echo("<b>");}

 

                else {echo("<a id=home_offerLink href=userlist.php?y=3&a=$a&s=$i&email_search=$email_search>");}

               

                if ($i == $s) {echo("</b>");}

                else {echo("</a>");}

               

            }

            echo("</p>");

        }

       

 

 

 

echo("

<center>

<table align=center border=0 cellpadding=2 width=90%>

 

");

       

 

for ($i = 0; $i < mysql_num_rows($res); $i++) {

          $id= mysql_result($res, $i, "id");

          $title= mysql_result($res, $i, "title");

          $filename= mysql_result($res, $i, "filename");

          $title=stripslashes($title);

          $title=stripslashes($title);

          $summary= mysql_result($res, $i, "summary");

          $summary=stripslashes($summary);

      $summary=stripslashes($summary);

                  $startdate= mysql_result($res, $i, "startdate");

 

 

//      $date= mysql_result($res, $i, "date");

          $key1= mysql_result($res, $i, "key1");

          $key2= mysql_result($res, $i, "key2");

          $key3= mysql_result($res, $i, "key3");

           

if($key1) {$key=$key1;}

if($key2) {$key=$key . " $key2";}

if($key3) {$key=$key . " $key3";}

 

 

 

 

$key=str_replace(" ","-",$key);

 

Link to comment
Share on other sites

change order by startdate desc which means largest value first ...

 

to .. order by startdate ASC (ascending order).

 

Tip - store dates in the yyyy-mm-dd format. Makes comparisons and calculations a breeze. You can always format outputted dates any way you want.  Using your date format will cause trouble when you look at the period November 2006 to January 2007, for example.

Link to comment
Share on other sites

Thanks for the reply not quite what I am looking for..

 

 

I am having no problems displaying the date and or ordering from latest events in 2007 to eairlest.  I am wanting to order the event by current date meaning if I have 12 events in April I want to list the events in April first.  Then the events in May June and July. When May comes around I want to be able to show Mays at the top then june and july. Is there a possible way to do this?

Link to comment
Share on other sites

let me repost the question maybe I will get some help on how to accomplish this so I am going to reword maybe I wasnt clear hopefully I am this time

 

 

have issues with ordering I have values stored in the database as datetime values when pulled from the database they display as

 

Y-m-d = 2007-04-30

 

When ordering as follows

 

order by startdate desc it displays the most current according to the startdate of the event for example

 

 

 


select Bla, Bla,Bla, startdate from events where event=1 order by startdate desc"]select Bla, Bla,Bla, startdate from events where event=1 order by startdate desc  

 

this will display all dates in the furture on down

 

What I am wanting to display all events that are in the current month starting from the current day that it is for example

 

todays date 2007-04-22 April

 

April Events

 

event 1 2007-04-22

event 2 2007-04-23

event 3 2007-04-24

event 4 2007-04-24

 

May events

event 1 2007-05-22

event 2 2007-05-23

event 3 2007-05-24

event 4 2007-05-24

 

June Events

 

 

event 1 2007-06-22

event 2 2007-06-23

event 3 2007-06-24

event 4 2007-06-24

 

 

and so on: and if there are no events for furture dates then display older events prior to April events.

 

 

Below is some code I am working with I am wondering if there is a way to do this with the following code or do I have to make seperate statements for each month. Any help wold be greateful

 

Thanks

 

 

 

 

 

$lim=20;  

  if (!isset($s) || $s < 1 || !is_numeric($s)) {  
            $s = 1;  
        }  

     $start = ($s - 1) * $lim;  

/////   Current Time Value and Format displays as 2007-m-d  Hour:min:sec
$time=date("Y-m-d H:m:s");  


//// Explode and seperate the date from the time create a array which consists of array 0 and 1

//// Array 0 = Date      Array 1 = Time

$time_array = explode( ' ',$time);  


//////  Explode date Array to get Year Month Day Values 

$time2 = explode("-", $time_array[0]); 

///////Day Month Year Values created a vairables 

$day1=$time2[2];  // displays in format 01 day - 31 days depends on day
$month1=$time2[1];  /// displays in format 01 month - 12 month depends on month
$year1=$time2[0];    /// Displays as 2007 or whatever year it is


//select information from database to be displayed  and counted for page results        
       
     $fquery = "select id,title,summary,hits,status,key1,key2,key3,filename,startdate from pr where event=1 ";  

   

  /// Counts pages to display page1 page 2 and so on       
        $countpages = $fquery;  


//// order statement and limit number of pages

        $fquery = $fquery . "order by startdate desc limit $start, $lim";  



//// 
        $res = mysql_query($fquery);  
        $pages = ceil(mysql_num_rows(mysql_query($countpages)) / $lim);  
      
//// If pages greater then on based on limit then echo extra pages and display results accord.


  if ($pages > 1) {  
            echo("<p align=left style=\"font-size: 85%\">");  
            for ($i = 1; $i <= $pages; $i++) {  
                  
                if ($i == $s) {echo("<b>");}  

                else {echo("<a id=home_offerLink href=userlist.php?y=3&a=$a&s=$i&email_search=$email_search>");}  
                  
                if ($i == $s) {echo("</b>");}  
                else {echo("</a>");}  
                  
            }  
            echo("</p>");  
        }  
          
          

          
        echo("  
<center>  
<table align=center border=0 cellpadding=2 width=90%>  

");  
          
  
//// Loop through results create vairables for each result


                
        for ($i = 0; $i < mysql_num_rows($res); $i++) {  
           $id= mysql_result($res, $i, "id");  
           $title= mysql_result($res, $i, "title");  
           $filename= mysql_result($res, $i, "filename");  
           $title=stripslashes($title);  
           $title=stripslashes($title);  
           $summary= mysql_result($res, $i, "summary");  
           $summary=stripslashes($summary);  
       $summary=stripslashes($summary);  
                  $startdate= mysql_result($res, $i, "startdate");  



///// display results order results


echo results  

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.