r2ks Posted December 27, 2012 Share Posted December 27, 2012 I have a Table. Name and Room Number is being pulled from a database, I would also like some other Placed in time cells where would I begin? so for example, Dan Dallas has Labs at 10:00 and CT at 12:00. I would like the word lab to appear in the 10:00 cell and CT in the 12:00 cell PtFirstName RoomNum 8:00 8:30 9:00 9:30 10:00 11:00 11:30 12:00 Dan,Dallas 303 Mike,Smith 304 Mike,Smith 304 Mike,jones 306 Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 27, 2012 Share Posted December 27, 2012 Are you saying you want to build a chart (table) with time of day on the x-axis and a person's name on the y-axis? Is the time stored in a datetime format? Quote Link to comment Share on other sites More sharing options...
r2ks Posted December 27, 2012 Author Share Posted December 27, 2012 (edited) PtFirstName RoomNum 8:00 8:30 9:00 9:30 10:00 11:00 11:30 12:00 Dan,Mcnulty 303 Mike,Smith 304 Mike,Smith 304 Mike,jones 306 Edited December 27, 2012 by r2ks Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 27, 2012 Share Posted December 27, 2012 Post your code, and we can help. Also, in the future, answer ALL of the questions people ask you. Quote Link to comment Share on other sites More sharing options...
r2ks Posted December 28, 2012 Author Share Posted December 28, 2012 Good Evening,Jessica. I apologize I thought in my last Post I did reply. However it did not go thorough. Yes lemmin That is correct please see the attached screen shot. Jessica, I would past code however I am using Dreamweaver CS5 for the beging of this. I have 4 Tables patient room datetime Treatment My question would be that how would I go about getting said treatment to populate under a 9:30 Cell. PTid is the primary Key in the Patient Tabel and I am Linking all the Tabels back to that PtID Thank You I am not Asking any one to do this for me just point me in the right direction.. Please see Screen Shot Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 28, 2012 Share Posted December 28, 2012 Step 1: Stop using Dreamweaver. Quote Link to comment Share on other sites More sharing options...
r2ks Posted December 28, 2012 Author Share Posted December 28, 2012 Nice Jessica, I did not ask you about Dreamweaver .... and what was this Statment you wrote "Also, in the future, answer ALL of the questions people ask you." Do not Correct me and then do the same thing.. if you do not want to help me or give me helpful information then do not repond to my post I did not come here for some one to Bust my Balls...I am looking for Help.. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 28, 2012 Share Posted December 28, 2012 You're the one looking for help. Therefore, if people need more information to help you, you are the one who is hurt if you don't give all the information. If I only answer part of your request for help, it only hurts you still. So... get used to it kid. "Jessica, I would past code however I am using Dreamweaver CS5 for the beging of this." The answer IS to stop using Dreamweaver, if you want to do actual development. If you don't have any code, we can't help you. Quote Link to comment Share on other sites More sharing options...
r2ks Posted December 28, 2012 Author Share Posted December 28, 2012 Code Post, <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test_cal", $con); $result = mysql_query("SELECT * FROM patient,room,treatment WHERE room.idPatient = patient.idPatient "); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Room Number</th> <th>8:30 am</th> <th>9:30 am</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['PtFirstName'] . "</td>"; echo "<td>" . $row['PtLastName'] . "</td>"; echo "<td>" . $row['RoomNum'] . "</td>"; echo "<td>". $row ['TreatmentType']. "</td>"; echo "<td>" . $row ['TreatmentType']. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 28, 2012 Share Posted December 28, 2012 You need to also select the time, then compare if the time the appointment is at is the time you're trying to print. Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 28, 2012 Share Posted December 28, 2012 The logic that I would use would consider each blank cell as an increment to get to your desired cell. For example, if you want to place the "treatment" under 10:00, and the times start at 8:00 with increments of 30 minutes, you have four cells to print before you get to the cell that should contain the output. You also have to consider the total and output extra cells to fill in the table. The trick is performing the math on your dates. That is why it's important to know what type of data your times are stored as. If they are stored as a datetime, you can actually perform the math in your query using a static datetime string that would represent the FIRST column (eg. TIME_TO_SEC(datetime - '2012-12-28 8:00:00')). This should leave you with a string parsed into a timestamp containing the number of seconds between your start time and the row's time value. The next step is to perform the logic. It would follow something like this: $number_of_time_cols = 6; while ($row = mysql_fetch_array($result)) { $blank_cols = $row['seconds'] / (30*60);//seconds in 30 minutes echo '<tr>'; echo '<td>'.$row['PtFirstName'].'</td>'; echo '<td>'.$row['PtLastName'].'</td>'; echo '<td>'.$row['RoomNum'].'</td>'; //print blank cells for ($i=$blank_cols;$i>0;$i--) echo '<td></td>'; //print time in correct cell echo '<td>'.$row['datetime'].'</td>'; //print extra blank cells for ($i=$number_of_time_cols;$i>1;$i--) echo '<td></td>'; //end row echo '</tr>'; } Quote Link to comment Share on other sites More sharing options...
Barand Posted December 28, 2012 Share Posted December 28, 2012 Whenever I have to produce this sort of output I generate blank arrays with the timeslots as the keys. $schedule = array ( '08:00' => '', '08:30' => '', '09:00' => '', '09:30' => '', '10:00' => '', '10:30' => '', '11:00' => '', '11:30' => '', '12:00' => '', '12:30' => '' // etc ); Then all I need do is drop the treatments into the element for that time $schedule[$timeslot] = $treatment; Then it's just a matter of printing the array columns. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted December 28, 2012 Share Posted December 28, 2012 The way I'd do this, is by looping through all of the time slots to build the table. As that's what you're looking to do. Then, for each loop checking to see if there is an appointment for said slot, and if there is print the info. Just like what Barand just posted and example of. Of course, this requires that you ready the datasets for output before you start to print the array. Which means moving all of the PHP code up before you send any HTML to the client. This is called separation of concerns, and is one of the most important aspects to create flexible, simple and powerful code. Something which DW does not do, and is one of the many reasons why not to use it for development. 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.