assgar Posted March 23, 2008 Share Posted March 23, 2008 Hi I am trying to display appointments in a database and would like to display all appointments for a week. The time of the day appears on the left and vertical columns with the names of appointments on the right. The code below only generates a single column of names. Would Time Mon Tue Wed Thu Fri Sat Sun ---------------------------------------------------------------------- 07:00AM name name name name name name name ---------------------------------------------------------------------- 07:15AM name name name name name name ------------------------------------------------------------ to ------------------------------------------------------------ 04:00PM name name <? function calendar_event_list_play($date $db_host, $db_user, $db_password, $db_id) { //connnect to database script here /**---------------get first day of the week for date ---------------**/ /**subtract the difference between monday of the week and start date from start_date for the start_date**/ $new_start = "2008-03-04"; /**-------------------------week day dates--------------------------**/ //monday $date_day1 = date("Y-m-d",strtotime($new_start)); $week_day1 = "Mon";//550 //tuesday $wk_day2 = strtotime($new_start); $date_day2 = date("Y-m-d",strtotime("+1 days",$wk_day2)); $week_day2 = "Tue";//551 //wednesday $wk_day3 = strtotime($new_start); $date_day3 = date("Y-m-d",strtotime("+2 days",$wk_day3)); $week_day3 = "Wed";//552 //thursday $wk_day4 = strtotime($new_start); $date_day4 = date("Y-m-d",strtotime("+3 days",$wk_day4)); $week_day4 = "Thu";//553 //friday $wk_day5 = strtotime($new_start); $date_day5 = date("Y-m-d",strtotime("+4 days",$wk_day5)); $week_day5 = "Fri";//554 //saturday $wk_day6 = strtotime($new_start); $date_day6 = date("Y-m-d",strtotime("+5 days",$wk_day6)); $week_day6 = "Sat";//555 //sunday $wk_day7 = strtotime($new_start); $month_day7 = date("F d",strtotime("+6 days",$wk_day7)); $date_day7 = date("Y-m-d",strtotime("+6 days",$wk_day7)); $week_day7 = "Sun";//556 /************************configuration*************************/ $add_time = 900; //15 min appointment time interval $start_time = "08:00:00"; $end_time = "16:00:00"; $status = A; /*************** this section displays the appointments***********/ //search area display area layer and table echo "<table width=\"100%\" border=\"0\">"; echo"<tr align=\"center\" bgcolor=\"#FFFFFF\" height=\"\">"; echo" <td width=\"100%\" > <div id=\"Layer2\" style=\"position:absolute;\"> <div id=\"pat-dash-scroll-box2\" style=\"overflow: \">\n"; //table begins echo "<table width=\"98%\" height=\"332\" left =\"4\" \">\n"; /**-------------------declare arrays-----------------**/ //Storing the rows rather than outputting them immediately //declare arrays for availablility $avail_day1 = array();//monday $avail_day2 = array();//tuesday $avail_day3 = array();//wednesday $avail_day4 = array();//thursday $avail_day5 = array();//friday $avail_day6 = array();//saturday $avail_day7 = array();//sunday //declare arrays for events $event_day1 = array();//monday $event_day2 = array();//tuesday $event_day3 = array();//wednesday $event_day4 = array();//thursday $event_day5 = array();//friday $event_day6 = array();//saturday $event_day7 = array();//sunday //loop through the 7 days of the week to load arrays for($i = 0; $i < 7; $i++) { //start with Monday: $day = 550; $day = $day + $i;//increment day code //increment day to the end date of week $wk_start = strtotime($new_start); $event_date = date("Y-m-d", strtotime("+$i days", $wk_start)); /**-------get availability config and event type info----**/ $query = "SELECT DISTINCT(a.time_id), a.start_time, a.end_time, c.colour FROM available a, type_display c WHERE a.type_code = c.type_code AND '$event_date' BETWEEN a.start_date AND a.end_date AND a.week_day = '$day' GROUP BY a.start_time"; $result = mysqli_query($mysqli, $query) or die('Error, query failed'); while($row = mysqli_fetch_array($result)) { SWITCH($i) { case 0: $avail_day1[] = $row; break; case 1: $avail_day2[] = $row; break; case 2: $avail_day3[] = $row; break; case 3: $avail_day4[] = $row; break; case 4: $avail_day5[] = $row; break; case 5: $avail_day6[] = $row; break; case 6: $avail_day7[] = $row; break; } } /**----------------appointment search by date-------------------**/ $query = "SELECT a.event_id, a.event_date, a.event_time, a.duration, a.event_type, p.last_name FROM cal_appointment a, pat_patient p WHERE a.patient_id = p.patient_id AND a.status = '$status' AND a.event_date = '$event_date' GROUP BY a.event_id, a.event_date, a.event_time, ORDER BY a.event_time, p.last_name "; $result = mysqli_query($mysqli, $query) or die('Error, query failed'); while($row = mysqli_fetch_array($result)) { SWITCH($i) { case 0: $event_day1[] = $row; break; case 1: $event_day2[] = $row; break; case 2: $event_day3[] = $row; break; case 3: $event_day4[] = $row; break; case 4: $event_day5[] = $row; break; case 5: $event_day6[] = $row; break; case 6: $event_day7[] = $row; break; } } } for($i = 0; $i < 7; $i++) { //Loop to display the work hours for($time = $start_time; $time <= $end_time; $time += $add_time) { //format 24 hour time interval for passing via url $interval_24hr = date("H:i:s", $time); //loop through array to diaplay event type colour and labeling foreach ($avail_day1 as $group_segment) { /**---------------event type display-------------------------**/ //diaplay event type colour and labeling to event end time if($interval_24hr >= $group_segment['start_time'] && $interval_24hr <= $end_time) { $seg_colour = "#".$group_segment['colour']; $time_id = $group_segment['time_id']; } //limit diaplay event type colour and labeling to event end time elseif($interval_24hr > $end_time) { $seg_colour = ""; } } /**-----------------------event time listing------------------------**/ echo "<tr>"; //Output the time interval label echo"<td width=\"8%\" height=\"15\" bgcolor=\"\" align=\"center\"> <div id=\"cal-number\" style =\"\"> <ul> <li>".date("h:i A", $time)."</li> </ul> </div> </td>"; //loop to display patient appointments foreach ($event_day1 as $event) { list($event_hr,$event_min,$event_sec) = split(":",$event['event_time']); //convert event time for comparison $event_time = mktime($event_hr, $event_min, $event_sec); //Event falls into this hour if($event_time >= $time && $event_time < ($time + $add_time)) { //event id $event_id = $event['event_id']; //patient id $patient_id = $event['patient_id']; //format patient name if(empty($event['last_name'])) { $patient_name = $seg_desc; } else { $patient_name = $event['last_name']; } //format date $db_event_date = $event['event_date']; foreach ($avail_day1 as $group_segment) { if($interval_24hr >= $group_segment['start_time'] && $interval_24hr <= $end_time) { $seg_colour = "#".$group_segment['colour']; $time_id = $group_segment['time_id']; } } //appointment type colour if(empty($patient_name)) { $bgcolor = $seg_colour; } echo "<td width=\"12%\" height=\"10\" bgcolor=\"$seg_colour\" align =\"left\"> <a href =\"../calendar_form.php? u_time=$interval_24hr&u_date=$db_event_date\"> $name </a></div></td>\n"; }//end if }//end foreach echo "</tr>"; }//end for } echo "</table>"; echo "</td>"; echo "</tr>"; echo "</div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/97448-solved-multi-column-data-display/ Share on other sites More sharing options...
assgar Posted April 20, 2008 Author Share Posted April 20, 2008 Hi thanks for responding After various approaches that worked partially this is the solution. I am open to suggestions on improving on it. NOTE:I have temporarily removed the appointments loop to focus on the event type looping. <? //work hours $min_start1 = "09:30:00";//earliest appointment $start_time = "09:00:00";//office hours $end_time = "05:00:00"; //get availability nfo /** selected data time_id, week_day, start_date, end_date, start_time, end_time, colour in array**/ $avail_days; //availaibility /**selected data event_id, event_name, event_date, event_time in array**/ $events;//appointment echo"<table>"; //Loop over the hours for ($time = $start_time; $time <= $end_time; $time += $add_time) { //format 24 hour time interval for passing via url $interval_24hr = date("H:i:s", $time); /**-----------------------event time listing and event type------------------**/ echo "<tr>"; //Output the time interval label echo"<td width=\"8%\" height=\"15\" bgcolor=\"\" align=\"center\"> <ul> <li>".date("h:i A", $time)."</li> </ul> </td>"; /**----------------------event type display------------------------------**/ //loop through array to diaplay event type colour and labeling foreach ($avail_days as $avail_day) { //day of the week Mon to sun $seg_day = $avail_day['week_day']; //diaplay event type colour and labeling to event end time //monday if($seg_day == 1 && $interval_24hr >= $avail_day['start_time'] && $interval_24hr <= $end_time) { $colour1 = "#".$avail_day['colour']; } elseif($seg_day == 1 && $interval_24hr > $end_time || $seg_day == 1 && $interval_24hr < $min_start1) { $colour1 = "#ebeae0";//default background colour } //tuesday if($seg_day == 2) { /*note: for tuesday to sunday not listed for space reasons it is the same as for monday except $colour2 etc is used*/ ..... } /**----------------------event--------------------**/ /*loop to provide appointment linked to appropriate event time slot goes here*/ /**------------------dynamic looping rows and columns--------------**/ echo'<td width="13%" height="12" bgcolor="$colour1"> $event_name1</td> <td width="13%" height="12" bgcolor="$colour2"> $event_name2</td> <td width="13%" height="12" bgcolor="$colour3"> $event_name3</td> <td width="13%" height="12" bgcolor="$colour4"> $event_name4</td> <td width="13%" height="12" bgcolor="$colour5"> $event_name5</td> <td width="13%" height="12" bgcolor="$colour6"> $event_name6</td> <td width="13%" height="12" bgcolor="$colour7"> $event_name7</td>"; echo"</tr>\n'; } echo"</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/97448-solved-multi-column-data-display/#findComment-521976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.