Jump to content

Recommended Posts

I have this code:

 

<?php

$field_qry = mysql_query("SELECT * FROM has_had_projects")or die(mysql_error()); 
	$field = mysql_num_fields($field_qry);
	while($row = mysql_fetch_array($field_qry)) {
		for($i = 0; $i < $field; $i++) {
			$names = mysql_field_name($field_qry, $i);
			$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);         
			$myArr[] = str_replace($numbers, '', $names);
		}		
	}

	$excel=new ExcelWriter();
	$excel->writeLine($myArr);

	$val_qry = mysql_query("SELECT * FROM has_had_projects")or die(mysql_error());

	$count_rows = mysql_num_fields($val_qry);
	while($numbered_rows = mysql_fetch_array($val_qry)) {
		for($i = 0; $i < $count_rows; $i++) {
			$arr[] = $numbered_rows[$i];
			}
		}

	$excel->writeLine($arr);		
	$excel->send('has_had_projects');

?>

 

It works fine if there is just one record in the DB but as soon as there is two or more records the $myArr var is repeated across the top of the spreadsheet instead of just adding a new row of data.

 

Did that make sense?

Link to comment
https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/
Share on other sites

ok i have almost got it figured out... i have a new problem now

 

code:

 

<?php $name = "projectlist";

$excel=new ExcelWriter();

$myArr=array("Id","Project","Project Id","PM","Designer","PM","Writer","PM","Designer","PM","Christine","PM","Designer","PM","Julie","PM","Designer","PM","Proofreading","PM","Layne","PM","Programming","PM","Testing");
$excel->writeLine($myArr);

	$val_qry = mysql_query("SELECT * FROM has_had_projects")or die(mysql_error());

	while($num_rows = mysql_fetch_object($val_qry)) {
		$arr[] = $num_rows->id;
		$arr[] = $num_rows->project;
		$arr[] = $num_rows->project_id;
		$arr[] = $num_rows->pm1;
		$arr[] = $num_rows->designer1;
		$arr[] = $num_rows->pm2;
		$arr[] = $num_rows->writer;
		$arr[] = $num_rows->pm3;
		$arr[] = $num_rows->designer2;
		$arr[] = $num_rows->pm4;
		$arr[] = $num_rows->christine;
		$arr[] = $num_rows->pm5;
		$arr[] = $num_rows->designer3;
		$arr[] = $num_rows->pm6;
		$arr[] = $num_rows->julie;
		$arr[] = $num_rows->pm7;
		$arr[] = $num_rows->designer4;
		$arr[] = $num_rows->pm8;
		$arr[] = $num_rows->proofreading;
		$arr[] = $num_rows->pm9;
		$arr[] = $num_rows->layne;
		$arr[] = $num_rows->pm10;
		$arr[] = $num_rows->programming;
		$arr[] = $num_rows->pm11;
		$arr[] = $num_rows->testing;
		}

	$excel->writeLine($arr);
	$excel->send($name); ?>

 

When I dump out the results and run the script I get an excel spreadsheet but the results are displayed on one row instead of individual rows... any ideas on how to fix this?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.