Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/272419-html-table-and-mysql-data/
Share on other sites

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

post-77491-0-85152900-1356653298_thumb.jpg

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..

 

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.

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);

?>

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>';
}

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.

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.

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.