Solved

Using arrays in a daily calendar schedule

Posted on 2007-03-30
2
188 Views
Last Modified: 2008-02-01
I found a really nice code to create a weekly calendar schedule on HotScripts, the author's name is PitaGyros. The code is based entirely on arrays. I adapted it to my needs, and I almost have it working as I want it to.What the code will do, is display the events that will run on particular day and show it's length. For example...
I have an event that will run at 11:00 and lasts 30 minutes:
10:45 nothing
11:00 Event
11:15
11:30nothing
11:45nothing

My problem is that the if statement that controls the line to print out the event is not working right. It will print out the following:
11:00 Event
11:15          Event
11:30
11:45 nothing

Anyways, here's the code. I'm not very good at using arrays, and I'm thinking this code uses multidimensional ones. If anyone can help me at least better understand how it works I'll really appreciate it!

$query = "SELECT press_id, section_name as name, ".
             "g_lstpte, g_prsstr, g_prsstp, press_date, prd_dte ".
             "FROM press_schedule ".
             "INNER JOIN sections ON ".
             "press_schedule.section_id=sections.section_id ".
             "WHERE press_date=from_unixtime($thisdate)";

$res = mysql_query($query);
echo '<table border="1">';
echo '<caption>Events for '.date('M-d-Y',$thisdate).'</caption>';
echo '<tr>';
echo '<th>&nbsp</th>';
echo '<th>Section Name</th>';
echo '</tr>';

while (($myrow = mysql_fetch_row($res)) != false)
{
  $db_id = $myrow[0];
  $db_time_start = substr($myrow[2], 0 , 5);
  $db_time_middle = substr($myrow[3], 0, 5);
  $db_time_end = substr($myrow[4], 0 , 5);
  $id[$db_time_start] = $myrow[0];
  $entry[$db_id]["name"] = $myrow[1];
  $entry[$db_id]["rowspan"] = diffTimeAbs($db_time_start, $db_time_end) / 15;
  $time = $db_time_start;
  $diffTimeAbs = diffTimeAbs($time, $db_time_end);
  while ($diffTimeAbs > 0)
  {
    $id[$time] = $id[$db_time_start];
      $time_hour = substr($time, 0, 2);
      $time_minute = substr($time, 3, 2) + 15;
      if ($time_minute == "60")
      {
        $time_hour++;
        $time_minute = "00";
      }
      if (strlen($time_hour) < 2) $time_hour = "0" . $time_hour;
      $time = $time_hour . ":" . $time_minute;
      $diffTimeAbs = diffTimeAbs($time, $db_time_end);
  }
}

for ($time_hour = 0; $time_hour < 24; $time_hour++)
{
  if (strlen($time_hour) < 2) $time_hour = "0" . $time_hour;
  for($time_minute = 0; $time_minute < 60; $time_minute += 15)
  {
    if (strlen($time_minute) < 2)  $time_minute = "0" . $time_minute;
      $time = $time_hour . ":" . $time_minute;
      echo '<tr>';
      echo '<td bgcolor="lightblue">'.$time.'</td>';
      if($entry[$id[$time]])
      {
        echo '<td bgcolor="'.$bgcolor[0].'"';
        echo 'rowspan = "'.$entry[$id[$time][0]]["rowspan"].'">';
        echo $entry[$id[$time][0]]["name"];
      } else {
        echo '<td bgcolor="'.$bgcolor[0].'"';
        echo 'rowspan = "'.$entry[$id[$time][0]]["rowspan"].'">';
        echo $entry[$id[$time][0]]["name"];
      }
      echo '<img align="right" src="./img/pixel.gif" border="0"';
      echo ' height="'.($entry[$id[$time][0]]["rowspan"]*5).'">';
      echo '</td>';
      echo("</tr>");
  }
}
echo("</table>");
0
Comment
Question by:horalia
2 Comments
 
LVL 12

Accepted Solution

by:
str_kani earned 500 total points
ID: 18827650
I doubt this section...

      if($entry[$id[$time]])
      {
        echo '<td bgcolor="'.$bgcolor[0].'"';
        echo 'rowspan = "'.$entry[$id[$time][0]]["rowspan"].'">';
        echo $entry[$id[$time][0]]["name"];
      } else {
        echo '<td bgcolor="'.$bgcolor[0].'"';
        echo 'rowspan = "'.$entry[$id[$time][0]]["rowspan"].'">';
        echo $entry[$id[$time][0]]["name"];
      }

i do not see any difference in the if part and the else part ...
0
 

Author Comment

by:horalia
ID: 18853128
I think too much caffeine was not making me look straight. I was able to figure out the issue by looking at the if statements again.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question