Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/239091-grouping-results-from-recordset/
Share on other sites

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.