Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using arrays in a daily calendar schedule

Posted on 2007-03-30
2
Medium Priority
?
197 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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 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