SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why Does This Give Me An Empty First Array?

    I have a problem with the following piece of code.

    PHP Code:
    echo "<br /><b>On Today's Schedule:</b><br />"

    $duration 0;
     
    while (
    $row mysql_fetch_array ($result)) 

      if (
    $djname != $row['name']) 
      
    // not same name as the last time 
      
    {
         
    $programs[] = array('start' => $start'end' => $end'djname' => $djname); 
         
    $djname $row['name'];
         
    $start $row['start'];
         
    $end $row['end'];
         
    $duration 1;
      } 
      else 
      { 
         
    $end =  $row['end'];
         
    $duration += 1;
      } 


    if (
    $duration$programs[] = array('start' => $start'end' => $end'djname' => $djname);

    // now print out shows 
    foreach ($programs as $show

    echo 
    $show['start'] . ' - ' $show['end'] . ' : ' $show['djname'] . '<br />'

    Click

    Ignore the golden table, look at the bottom. Why is it tacking on an empty array at the beginning?

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Make this change
    PHP Code:
    $djname $row['djname'];
    $start $row['start'];
    $end $row['end'];
    $duration 1;
    $programs = array('start' => $start'end' => $end'djname' => $djname); 

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    Make this change
    PHP Code:
    $djname $row['djname'];
    $start $row['start'];
    $end $row['end'];
    $duration 1;
    $programs = array('start' => $start'end' => $end'djname' => $djname); 
    Actually, that change does help with the empty array at the beginning, but the end hours are not correct. Also, the last array is duplicated.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •