adambedford Posted June 11, 2011 Share Posted June 11, 2011 Hi, I have a table (tbl_ClassEntries) that stores appointment information. One of the fields is 'ce_recurrence' which stores what days of the week the appointment occurs. The info is stored as a comma separated string (eg. Monday, Wednesday and Thursday would be 'm,w,th'). I'm querying this table and returning all appointments matching a certain user (field called: ce_uid) however I'd like to show a day by day list of the appointments (there will be multiple each day). I'm thinking that I need to loop through the recordset and then explode the recurrence string but then I'm stuck and don't know where to go from there. Any help would be really appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/ Share on other sites More sharing options...
QuickOldCar Posted June 11, 2011 Share Posted June 11, 2011 'm guessing you now need to do something like a foreach loop. foreach($content as $value){ echo $value."<br />"; } or however would like to style and display it Posting what code you have helps greatly. Quote Link to comment https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/#findComment-1228424 Share on other sites More sharing options...
adambedford Posted June 11, 2011 Author Share Posted June 11, 2011 Thanks for the reply. I have the following code (simple stuff right now): $sql_find_schedule = "SELECT * FROM tbl_ClassEntries WHERE ce_uid = '{$u_info['u_id']}'"; $query_find_schedule = mysql_query($sql_find_schedule) or die(mysql_error()); while($find_schedule = mysql_fetch_array($query_find_schedule)) { $recurrence = explode($find_schedule['ce_recurrence']); } I'm trying to group the records by day of the week, so I need some way of seeing what day they occur on (ie. What the contents of $recurrence is) and then displaying them under that day. Its possible that they'll occur multiple times in one week. Quote Link to comment https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/#findComment-1228428 Share on other sites More sharing options...
QuickOldCar Posted June 11, 2011 Share Posted June 11, 2011 In the select statement itself you can add GROUP BY type to the end of your query. type being the day value you use. EDIT: You should be able to use a dropdown to change the day values by using a variable in the select statement. So can select which day would like to see the results for. Quote Link to comment https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/#findComment-1228440 Share on other sites More sharing options...
adambedford Posted June 11, 2011 Author Share Posted June 11, 2011 thanks for your suggestions. i need to view all days of the week (monday-friday) on the same page at the same time, however. Quote Link to comment https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/#findComment-1228496 Share on other sites More sharing options...
QuickOldCar Posted June 11, 2011 Share Posted June 11, 2011 OK The best way then is to do 5 queries grouping them by each day and display each of the results same page. Otherwise would have to sift through all the results creating new arrays and then exploding and foreach on each of those results. so an idea would be to group each value by day for all results. in your while() you now have an array of $recurrence I do not know which key is the date, but you will $recurrence_date = trim($recurrence[0]);//this is the first of the exploded group, change to date key if($recurrence_date == "monday") { $monday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "tuesday") { $tuesday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "wednesday") { $wednesday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "thursday") { $thursday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "friday") { $friday_group[] = $find_schedule['ce_recurrence']; } //now each is grouped in day arrays outside the while loop //now explode and echo all the results for each day in a foreach foreach($monday_group as $monday_array) { foreach($monday_array as $monday_results){ echo $monday_results."<br />"; } } //and do the others as well Maybe others know better ways, but I think the 5 queries each day is the best. Quote Link to comment https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/#findComment-1228509 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.