Solved

Using arrays in a daily calendar schedule

Posted on 2007-03-30
2
191 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

737 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