Array problem

From: Date: Sun, 21 Mar 2004 17:33:54 +0000
Subject: Array problem
Groups: php.general 
Request: Send a blank email to php-general+get-181091@lists.php.net to get a copy of this message
This has been confusing me a little for a few hours now. Heres a snip of my code which is causing the problem: $content = "<table border='0' cellspacing='0' cellpadding='5'>\n"; $content .= "<tr>\n"; $content .= "<td>&nbsp;</td>\n"; $tasks = new dbconnect; $tasks->connect(); $tasks->query("SELECT tid, tname FROM tasks"); while(list($tid, $tname) = $tasks->fetch_rows()) {
       $content .= "<td valign='top' align='center'><span class='highlight'>$tname</span></td>\n";
} $content .= "<td>&nbsp;</td>\n"; $content .= "</tr>\n"; $projects = new dbconnect; $projects->connect(); $projects->query("SELECT pid, pname FROM projects");
        * $columntotals = array();*
$colour = 0; while(list($pid, $pname) = $projects->fetch_rows()) {
       $tasks->data_seek(0);
       $rowtotal = 0;
       $count = 0;
       if ($colour % 2) {
           $bgcolour = "#FFFFFF";
       }
       else {
           $bgcolour = "#F9F9F9";
       }
       $colour++;
       $content .= "<tr>\n";
       $content .= "<td valign='top' align='center'><span class='highlight'>$pname</span></td>\n";
             while(list($tid, $tname) = $tasks->fetch_rows()) {
           $logs = new dbconnect;
           $logs->connect();
           $logs->query("SELECT SUM(hours) from logs WHERE pid = '$pid' AND tid = '$tid' AND date >= '$sdate' AND date <= '$edate'");
           list($sum) = $logs->fetch_rows();
                     if (!$sum) {
               $sum = 0;
           }
                     $rowtotal = $rowtotal + $sum;
           *$columntotals[$count] = $columntotals[$count] + $sum;*
           $count++;
                     $content .= "<td bgcolor='$bgcolour' align='center'>$sum</td>\n";
       }
       $content .= "<td align='center'><b>$rowtotal</b></td>\n";
} $content .= "</tr>\n"; $content .= "<tr>\n"; $content .= "<td>&nbsp;</td>\n"; $sumofcolumntotals = 0; for ($i=0; $i<sizeof($columntotals); $i++) {
       $sumofcolumntotals = $sumofcolumntotals + $columntotals[$i];
       $content .= "<td align='center'><b>$columntotals[$i]</b></td>\n";
} $content .= "<td align='center'><b>$sumofcolumntotals</b></td>\n"; $content .= "</tr>\n"; $content .= "</table>\n"; I have made the lines inwhich I know are causing problems in bold. Basicly, I am creating a report of some data and need to count up totals of each column and then again total the totals if you get me. Here is the errors I am getting. *Notice*: Undefined offset: 0 in *C:\WWW\Apache2\htdocs\php\coursework\reports_projects.php* on line *58* *Notice*: Undefined offset: 1 in *C:\WWW\Apache2\htdocs\php\coursework\reports_projects.php* on line *58* *Notice*: Undefined offset: 2 in *C:\WWW\Apache2\htdocs\php\coursework\reports_projects.php* on line *58* *Notice*: Undefined offset: 3 in *C:\WWW\Apache2\htdocs\php\coursework\reports_projects.php* on line *58 *Now I understand in a way why its happening, because im trying to insert into $columntotals something which isnt valid, but I can't think of a way to stop this at the moment. Hope to hear soon, thanks in advance guys. -noginn

« previous php.general (#181091) next »