Solved

Using arrays in a daily calendar schedule

Posted on 2007-03-30
2
185 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now