andy Posted March 30, 2006 Share Posted March 30, 2006 [!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--][!--fonto:Verdana--][span style=\"font-family:Verdana\"][!--/fonto--]I had this 'if else' statement which calls a function depending on whether a location or a date has been chosen from drop downs. The database has a field called 'depart_time' ie which is entered as UNIXTIME and has two rows, one for outward departure, and one for inward departure (flights) ie only their chronological difference indicates which. Although my solution for the location SQL query seems to have sorted the dates error, when searching by location, I can't figure out if I can alter my dates SQL to correct the problem when searching by month/year, or whether I should be looking elsewhere. BTW I'm fairly new to php/mySQL and this is me trying to correct someone elses code.See: [a href=\"http://www.travelforthearts.co.uk/shtml/master_detail.php?type=3&month=03&year=2006\" target=\"_blank\"]http://www.travelforthearts.co.uk/shtml/ma...th=03&year=2006[/a]where the 11th comes before the 8th. [b]OLD CODE[/b][code] <?php if($_GET['location'] && $_GET['type']) { $tours = $_TOURS->get_tours_by_location($_GET['type'],$_GET['location']); } elseif($_GET['month'] && $_GET['year']) { $tours = $_TOURS->get_tours_by_date($_GET['type'],$_GET['month'],$_GET['year']); } if(is_array($tours)) { foreach($tours as $key => $data) {?> <tr bgcolor="#FFFFFF" class="bodycopywht"> <td valign="top"><span class="style14"><a href="master_result.php?tid=<?php echo $data['tour_id']?>"><?php echo $data['tour_name'];?></a></span><span class="style6"><br> </span></td> <td align="center" valign="top" class="style14"><?php echo $data['day'].'/'.$data['month'].'/'.$data['year'];?></td> </tr> <?} }?>[/code][b]This was the old function for location:[/b][code]function get_tours_by_location($type,$location){ $SQL = 'SELECT tour.*, performances.performance_id, venues.venue_id, FROM_UNIXTIME(flights.depart_time,"%d") AS day, FROM_UNIXTIME(flights.depart_time,"%m") AS month, FROM_UNIXTIME(flights.depart_time,"%Y") AS year FROM tour LEFT JOIN performances ON performances.tour_id = tour.tour_id LEFT JOIN venues on performances.venue_id = venues.venue_id LEFT JOIN flights on flights.tour_id = tour.tour_id WHERE tour.tour_type LIKE("%'.$type.'%") AND venues.venue_location = "'.$location.'" GROUP BY tour.tour_id, venues.venue_location ORDER BY flights.depart_time ASC';[/code]... and this for date[code]function get_tours_by_date($type,$month,$year){ $SQL = 'SELECT tour.*, performances.performance_id, venues.venue_id, FROM_UNIXTIME(flights.depart_time,"%d") AS day, FROM_UNIXTIME(flights.depart_time,"%m") AS month, FROM_UNIXTIME(flights.depart_time,"%Y") AS year FROM tour LEFT JOIN performances ON performances.tour_id = tour.tour_id LEFT JOIN venues on performances.venue_id = venues.venue_id LEFT JOIN flights on flights.tour_id = tour.tour_id WHERE tour.tour_type LIKE("%'.$type.'%") AND FROM_UNIXTIME(flights.depart_time,"%m") = "'.$month.'" AND FROM_UNIXTIME(flights.depart_time,"%Y") = "'.$year.'" GROUP BY tour.tour_id, venues.venue_location ORDER BY flights.depart_time ASC';[/code][b]unfortunately it was returning the dates on the results page in the wrong order in some searches, so I changed the if else too:[/b][code] <?php if($_GET['location'] && $_GET['type']) { $tours = $_TOURS->get_tours_by_location($_GET['type'],$_GET['location']); } elseif($_GET['month'] && $_GET['year']) { $tours = $_TOURS->get_tours_by_date($_GET['type'],$_GET['month'],$_GET['year']); } if(is_array($tours)) { foreach($tours as $key => $data) {?> <tr bgcolor="#FFFFFF" class="bodycopywht"> <td valign="top"><span class="style14"><a href="master_result.php?tid=<?php echo $data['tour_id']?>"><?php echo $data['tour_name'];?></a></span><span class="style6"><br> </span></td> <td align="left" valign="top" class="style14"> <?php echo $data['day']?></td> </tr> <?} }?>[/code][b]and the functions to:[/b][code]function get_tours_by_location($type,$location){ $SQL = 'SELECT tour.*, performances.performance_id, venues.venue_id, DATE_FORMAT(MIN(FROM_UNIXTIME(flights.depart_time)),"%D %b %Y") AS day FROM tour LEFT JOIN performances ON performances.tour_id = tour.tour_id LEFT JOIN venues on performances.venue_id = venues.venue_id LEFT JOIN flights on flights.tour_id = tour.tour_id WHERE tour.tour_type LIKE("%'.$type.'%") AND venues.venue_location = "'.$location.'" GROUP BY tour.tour_id, venues.venue_location ORDER BY flights.depart_time ASC';[/code]and:[code]function get_tours_by_date($type,$month,$year){ $SQL = 'SELECT tour.*, performances.performance_id, venues.venue_id, DATE_FORMAT(MIN(FROM_UNIXTIME(flights.depart_time)),"%D %b %Y") AS day FROM tour LEFT JOIN performances ON performances.tour_id = tour.tour_id LEFT JOIN venues on performances.venue_id = venues.venue_id LEFT JOIN flights on flights.tour_id = tour.tour_id WHERE tour.tour_type LIKE("%'.$type.'%") AND FROM_UNIXTIME(flights.depart_time,"%m") = "'.$month.'" AND FROM_UNIXTIME(flights.depart_time,"%Y") = "'.$year.'" GROUP BY tour.tour_id, venues.venue_location ORDER BY flights.depart_time ASC';[/code][b]...which as I say sorted the location searches, but not the date searches[/b][!--sizec--][/span][!--/sizec--][!--fontc--][/span][!--/fontc--] Quote Link to comment Share on other sites More sharing options...
andy Posted April 2, 2006 Author Share Posted April 2, 2006 anyone? ....or should I post in another forum more suited. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.