logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 10-30-2013, 03:34 AM   #1
sydesign
 
Join Date: Jan 2011
Posts: 41
Default Help sorting MySQL results query by date

I am trying to figure out a way of sorting out results of my database by events past.

I have an events page and wish to display the next upcoming event, only showing one at a time and once the event is past i want the next event to show up there. I would like to keep the events in the database but only wish to show the next upcoming date in the future here.

Here is the code i have right now sorting the database by the earliest date:


PHP Code:
//Retrieves data from MySQL 
 
$data mysql_query("SELECT * FROM events WHERE active='yes' ORDER BY year ASC, month ASC, day ASC LIMIT 1") or die(mysql_error()); 
 
//Puts it into an array 
 
while($info mysql_fetch_array$data )) 
 {
   
   
$month $info['month'];
   
$month2 substr($month3);
  
   
$day $info['day'];
   
$year $info['year'];
   
$venue $info['venue'];
   
$title $info['title'];
   
$city $info['city'];
   
$state $info['state'];
   
$hour $info['hour'];
   
$minutes $info['minutes'];
   
$band $info['band'];
   
   
$ticketlink $info['ticketlink'];
   
   if (
$ticketlink != ""){ 
        
$ticketlink '<br /><span style="line-height:20px;text-transform:uppercase;" class="tickets">
       <a href="' 
.$ticketlink'" target="_blank" style="text-decoration:none;">Get your Tickets Now!</a></span>'
   } else { 
     
$ticketlink "<br /><a href='events/'>Tickets available soon!</a>"
   }
 } 
A big thanks in advance for any help! Thank you!
sydesign is offline   Reply With Quote
Old 10-30-2013, 08:34 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

you will need to compare date of the event date and date on the server.
this will need a function to formulate the date with ethe form you are using in our database

Code:
function compareDate ($i_sFirstDate, $i_sSecondDate)
{
        $arrFirstDate = explode ("/", $i_sFirstDate);
        $arrSecondDate = explode ("/", $i_sSecondDate);

        $intFirstMonth  = $arrFirstDate[0];
        $intFirstDay    = $arrFirstDate[1];
        $intFirstYear   = $arrFirstDate[2];

        $intSecondMonth = $arrSecondDate[0];
        $intSecondDay   = $arrSecondDate[1];
        $intSecondYear  = $arrSecondDate[2];

        $intDate1 = mktime(12, 0, 0, intval($intFirstMonth), intval($intFirstDay), intval($intFirstYear));
        $intDate2 = mktime(12, 0, 0, intval($intSecondMonth), intval($intSecondDay), intval($intSecondYear));

        return $a = round(abs($intDate2 - $intDate1) / 86400);
}

then you can use an if condition to compare the dates
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 10-30-2013, 06:55 PM   #3
sydesign
 
Join Date: Jan 2011
Posts: 41
Default

thank you! Though, I'm not too familiar with javascript or the code you have above and am not sure how to implement it. Would you be able to explain and show me how i would use that function?
sydesign is offline   Reply With Quote
Old 10-31-2013, 01:40 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

its PHP.
the function compares the difference between 2 dates
so an example of calling it might be

Code:
$datevent=$row['datevent']; ?/ clearlt edited to suit your database, and assuming the vent daye is a timestamp/datetime

$datevent = date("m/d/y",strtotime($datevent)); //formats the date


// The following compares the database  event date with the date on the server ( using date()    )  

if(compareDate( $datevent,date("m/d/y",time()))< ){


  //     echo your stuff
}
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:24 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com