Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table with schedule from mysql

Status
Not open for further replies.

9h1lo

Technical User
Sep 28, 2009
9
MT

Hi group

I am playing with a small scheduling app and am getting slightly stuck...

Basically I have a table showing different time blocks for every 15mins filled in from mysql..at the moment is coded really ugly and works slow as each <td> runs a query..now I am trying to fix it and have got the below to build the table:

echo "<table width=\"50%\" border=\"1\" cellpadding=\"0\" cellspacing=\"1\"><tr>";
$start = 7*60+0;
$end = 13*60+0;
for($time = $start; $time<=$end; $time += 15)
{
$minute = $time%60;
$hour = ($time-$minute)/60;

$ty= sprintf('%2d:%02d', $hour, $minute);
echo "<td width=\"100\" height=\"100\">\n";
echo $ty;
}
echo "</td>";

echo "</tr></table>";

now problem no.1. how do i make it start a new <tr> every 4 <td> ?

prob. 2. I want to show the data from mysql which co-incides from the current value of the time $ty

I have been playing with some code using "each" but it's messy and i'm banging my head now...I'm sure you 'gurus' can come up with a simple way to do it

 
ok solved prob no 1...maybe not the best way of doing it but it works...


echo "<table width=\"50%\" border=\"1\" cellpadding=\"0\" cellspacing=\"1\"><tr>";
$rowNum=0;
$start = 7*60+0;
$end = 13*60+0;
for($time = $start; $time<=$end; $time += 15)
{
if($rowNum > 3)
{
$rowNum = 0;
echo "</tr><tr>";
}
$minute = $time%60;
$hour = ($time-$minute)/60;

$ty= sprintf('%2d:%02d', $hour, $minute);
echo "<td width=\"100\" height=\"100\">\n";
echo $ty;
$rowNum++;
}

echo "</tr></table>";



now maybe someone could shed some light on no 2:
 
ok this is the best I could come up with....it works but don't think it makes sense running a query against the DB for every loop...I am sure it can be done with arrays and foreach...been up too long and just can't get my head around it...maybe someone can clean my code

mysql_select_db("intranet", $con);
echo "<table width=\"50%\" border=\"1\" cellpadding=\"0\" cellspacing=\"1\"><tr>";
$rowNum=0;
$start = 7*60+0;
$end = 19.80*60+0;
for($time = $start; $time<=$end; $time += 15)
{
if($rowNum > 3)
{
$rowNum = 0;
echo "</tr><tr>";
}
$minute = $time%60;
$hour = ($time-$minute)/60;
$ty= sprintf('%02d:%02d', $hour, $minute);
echo "<td width=\"100\" height=\"100\">\n";
echo $ty . "<br>";
$result = mysql_query("SELECT event_title FROM calendar_events WHERE event_time='$ty' AND event_day='$sel_day' AND event_month='$sel_month' AND event_year='$sel_year'");
while($row = mysql_fetch_array($result))
{echo $row['event_title'] ;}
$rowNum++;
}
echo "</tr></table>";
 
updated again...had to add some other minon stuff...it explains itself....

mysql_select_db("intranet", $con);
echo "<table width=\"50%\" border=\"1\" cellpadding=\"0\" cellspacing=\"1\"><tr>";
$rowNum=0;
$start = 7*60+0;
$end = 19.80*60+0;
for($time = $start; $time<=$end; $time += 15)
{
if($rowNum > 3)
{
$rowNum = 0;
echo "</tr><tr>";
}
$minute = $time%60;
$hour = ($time-$minute)/60;
$ty= sprintf('%02d:%02d', $hour, $minute);
echo "<td width=\"100\" height=\"100\">\n";
$result = mysql_query("SELECT event_title FROM calendar_events WHERE event_time='$ty' AND event_day='$sel_day' AND event_month='$sel_month' AND event_year='$sel_year'");
if(mysql_num_rows($result)>0){
$row = mysql_fetch_array($result);
echo $ty."<br>".$row['event_title'] . "<br>";
}else{
echo "<input type=\"radio\" name=\"time\" value=".$ty.">". $ty ;
}
$rowNum++;
}
echo "</tr></table>";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top