?
Solved

Using arrays in a daily calendar schedule

Posted on 2007-03-30
2
Medium Priority
?
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
str_kani earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
Suggested Courses

752 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