[thelist] Excel & PHP, Total Column SOLVED

Jay Blanchard jay.blanchard at niicommunications.com
Wed May 8 13:27:00 CDT 2002


<?
//set some variables
$alpha1 = b; <---second column, Excel spreadsheet
$alpha2 = $alpha1; <----a variable to increment from the known value
$numeric1 = 2; <----second row, Excel spreadsheet
$ax = mysql_num_fields($dbx)-1; <----the column fields, minus the first one
which holds fixed data
while($dbrow = mysql_fetch_row($dbx)){
	print("<tr>");
//gets and prints all of the columns
	$col_num = 0;
	foreach($dbrow as $key=>$value){
		if($dbrow[$col_num] > 0){
			print("<td>$dbrow[$col_num]</td>");
			}
		else {
			print("<td>&nbsp;</td>");
			}
		$col_num++;
		}
//increment the $alpha while decrement the # of columns to go b, c, d, e,
etc
while($ax > 1){
	$alpha2++;
	$ax--;
	}
//print the function for the cell
print("<td>=sum($alpha1$numeric1:$alpha2$numeric1)</td>");
//increment the row number for calcs on next row
$numeric1++;
	print("</tr>\n");
	}
?>

Another series of articles, PHP to Excel, the How-To! :)

Jay





More information about the thelist mailing list