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 Quote Link to comment Share on other sites More sharing options...
laPistola Posted December 4, 2008 Share Posted December 4, 2008 show us some code? Quote Link to comment 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); ?> Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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? 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.