Andrew R Posted December 4, 2008 Share Posted December 4, 2008 Hi there I have a table called routes. In this table I have a column called days which is in the format, MON-TUES-WED-THU-FRI-SAT-SUN. In my html I have 7 html boxes for the results to go into. The query I am using to search the table is SELECT * FROM routes where departure = '$a' && arrival = '$b' What I want to do is sort the results into the correct box. For example all the Mon routes would go into the Monday html box. How would I go about doing this? Would I create a number of arrays? I guess an inefficient way would be to create 7 queries but surely there’s a more dynamic way? Many thanks Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/ Share on other sites More sharing options...
laPistola Posted December 4, 2008 Share Posted December 4, 2008 show us some code? Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/#findComment-706334 Share on other sites More sharing options...
flyhoney Posted December 4, 2008 Share Posted December 4, 2008 <?php $query = "SELECT * FROM routes where departure = '$a' && arrival = '$b'"; $result = mysql_query($query); $routes = array(); while ($row = mysql_fetch_assoc($result)) { $routes[$row['day']][] = $row; } print_r($routes); ?> Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/#findComment-706335 Share on other sites More sharing options...
lanmonkey Posted December 5, 2008 Share Posted December 5, 2008 <?php $query = "SELECT * FROM routes where departure = '$a' && arrival = '$b'"; $result = mysql_query($query); $routes = array(); while ($row = mysql_fetch_assoc($result)) { $routes[$row['day']][] = $row; } print_r($routes); ?> So you have an array called $routes with everything nicley ordered in it. all you need to do is a foreach loop in each html box foreach($routes[MON] as $mon) { //output stuff here echo $mon; } foreach($routes[TUE] as $tue) { //output stuff here echo $tue; } somthing like that Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/#findComment-706675 Share on other sites More sharing options...
Andrew R Posted December 5, 2008 Author Share Posted December 5, 2008 Thanks for a million for the help . One thing when I try to output anything I get ArrayArray...... etc? Any ideas? Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/#findComment-706793 Share on other sites More sharing options...
flyhoney Posted December 5, 2008 Share Posted December 5, 2008 That means you are trying to print an array. Use print_r() to see the structure of the data you are trying to print. Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/#findComment-706855 Share on other sites More sharing options...
Andrew R Posted December 5, 2008 Author Share Posted December 5, 2008 How would I output specific fields inside each foreach statement? For example if I wanted output duration. Would I create another array for that? Link to comment https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/#findComment-706898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.