SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined offset?

    I'm having this problem.

    Notice: Undefined offset: 0 in c:\web\php4\wbmb\include\scheduletablebuilder.php on line 119

    This is an iterator script.
    Here is the entire code, with the problem line emphasized between comments
    PHP Code:
    <?php
    error_reporting 
    (E_ALL);
    include_once 
    'tablebuilder.php';

    /**
     * schedule table builder
     */
    class scheduleTableBuilder extends rowBuilder {
        
        
    /**
         * private
         * $schedule schedule data
         */
        
    var $schedule;
        
        
    /**
         * private
         * $output the xhtml output
         */
        
    var $output;
        
        
    /**
         * private
         * $colCount number of columns
         */
        
    var $colCount;
        
        
    /**
         * private
         * $timeIndex the time of 00:00:00 to keep everything synced
         */
        
    var $timeIndex;
        
        
    //! constructor
        /**
         * constructs scheduleTableBuilder object
         *
         * @param $colCount number of columns
         *
         * @return void
         */
        
    function scheduleTableBuilder($colCount) {
            
    $this->colCount $colCount;
            
    $this->timeIndex strtotime("00:00:00");
        }
        
        
    /**
         * creates the column headers
         *
         * @param $colCount number of columns
         */
        
    function columnHeaders() {
            switch (
    $this->colCount) {
                
    // week schedule
                
    case 5:
                    return 
    '<colgroup span="1" width ="2*" class="time"></colgroup><colgroup span="7" width ="3*" class="day"></colgroup>';
                    break;
                
    // day schedule
                
    case 6:
                    return 
    '<colgroup><col class="showpicture" /><col class="showinfo" /></colgroup>';
                    break;
                }
        }
        
        
    /**
         * suppose to add rows, but this collects all arrays for processing
         * 3-dimensional array. key = days (Mon-Sun)
         *
         * @param $row row by row dataset to be colected
         *
         * @return void
         */
        
    function addRow($row) {
            
    $this->schedule[$row['day']][] = 
                array(
                    
    "name" => $row['name'], 
                    
    "radioshow_id" => $row['radioshow_id'], 
                    
    "showstart" => ((strtotime($row['showstart'])) - $this->timeIndex), 
                    
    // 1 length = 60 minute slot
                    
    "length" => ((strtotime($row['showend'])-strtotime($row['showstart']))/3600)
                    );
        }
        
        
    /**
         * this does the "heavy calculating" to arrange all timeslots
         * starts at midnight and goes left to right, skipping a
         * column if a show is already there, then move onto next row
         *
         * @return string
         */
        
    function makeTable() {
            echo 
    '<pre>';
            
    var_dump($this->schedule);
            echo 
    '</pre>';
            
    $theDays = array( 'Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun' );
            
    $timeSpace = array( );
            
            for(
    $timeSlot 0$timeSlot 86400$timeSlot $timeSlot 3600) {
                
                
    $this->output .= "<tr>\n<td>".date("g:i a", ($timeSlot $this->timeIndex))."</td>\n";
                
                    for(
    $i 0$i <= 6$i++) {
                        
                        
    // if there are no schedules for a whole day
                        
    if ((!array_key_exists($theDays[$i], $this->schedule)) && ($timeSpace[$i] == )) {
                            
                            
    $this->output .= '<td rowspan="24">empty</td>';
                            
    $timeSpace[$i] = $timeSpace[$i] + 86400;
                            
                        }
                        
                        
    // something is already there
                        
    if ($timeSpace[$i] > $timeSlot) {
                                
                            
    // if there isn't anything there
                            
    } elseif ($timeSpace[$i] == $timeSlot) {
                                
                                
    // a show schedule fits
                                // -----------------------------------------------------
                                // -------------problem is on this line------------
                                // -----------------------------------------------------
                                
    if ($this->schedule[$theDays[$i]][0]['showstart'] == $timeSpace[$i]) {
                                
    // -----------------------------------------------------
                                // -----------------------------------------------------
                                // -----------------------------------------------------
                                    
                                        
    $this->output .= '<td rowspan="'.$this->schedule[$theDays[$i]][0]['length'].'"><a href="show.php?id='.$this->schedule[$theDays[$i]][0]['radioshow_id'].'">'.$this->schedule[$theDays[$i]][0]['name'].'</a></td>'."\n";
                                        
    $timeSpace[$i] = $timeSpace[$i] + (3600*$this->schedule[$theDays[$i]][0]['length']);
                                        
    array_shift($this->schedule[$theDays[$i]]);

                                
    // no schedule information left, but timeslots not filled
                                
    } elseif ((empty($this->schedule[$theDays[$i]][0])) && ($timeSpace[$i] < 86400)) {
                                    
                                    
    $slotsLeft = ((86400 $timeSpace[$i])/3600);
                                    
    $this->output .= '<td rowspan="'.$slotsLeft.'">empty</td>'."\n";
                                    
                                
    // next schedule is far ahead
                                
    } elseif ($this->schedule[$theDays[$i]][0]['showstart'] > $timeSpace[$i]) {
                                    
                                    
    $slotsLeft = (($this->schedule[$theDays[$i]][0]['showstart'] - $timeSpace[$i])/(3600));
                                    
                                    
    $this->output .= '<td rowspan="'.$slotsLeft.'">empty</td>'."\n";
                                    
    $timeSpace[$i] = $timeSpace[$i] + (3600*$this->schedule[$theDays[$i]][0]['length']);
                                    
                            }
                            
                        }

                    }
                
                
    $this->output .= "</tr>\n";
                
            }
            
            
    $this->output .= '</table>';
            
        }
        
        
    /**
         * takes property $schedule and forms an output
         */
        
    function tableEnder() {
            
            
    $this->makeTable();
            return 
    $this->output;
            
        }
        
        
    /**
         * return timeIndex
         */
        
    function timeIndex() {
            return 
    $this->timeIndex;
        }
        
    }

    ?>
    I had this problem before. And I just had to fix a conditional. However this time it seems all conditionals are correct, and I don't know what to do now.

  2. #2
    SitePoint Member AlexBrina's Avatar
    Join Date
    Jul 2004
    Location
    office.bh.mg.br
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's an array error (duh!), the schedule is filled up by the addRow method and I didn't see any call to addRow, check if u call addRow from the main script.

    maybe your thread should've been posted to the PHP forum, maybe.
    Alex Brina
    "...sempre q eu tirar a cabeça fora d'agua eu dou um alô..." JC

  3. #3
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I realise this should be in regular php forums. I tried deleting a minute after making this thread.

    And yes, the array is right, that is why I put the var_dump(); line there so I can make sure the array exists.

    If I keep using array_shift($this->schedule[$theDays[$i]]);, then would empty($this->schedule[$theDays[$i]][0]) return true? Maybe this might be it.


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
  •