dennismonsewicz Posted October 14, 2008 Share Posted October 14, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/ Share on other sites More sharing options...
trq Posted October 14, 2008 Share Posted October 14, 2008 Ive no idea how ExcelWriter works but surely you'll want to move your call to writeLine into your while loop? Quote Link to comment https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/#findComment-665461 Share on other sites More sharing options...
dennismonsewicz Posted October 14, 2008 Author Share Posted October 14, 2008 well the code browser didn't like that very much... it created an infinite loop! Quote Link to comment https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/#findComment-665553 Share on other sites More sharing options...
dennismonsewicz Posted October 14, 2008 Author Share Posted October 14, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/#findComment-665577 Share on other sites More sharing options...
dennismonsewicz Posted October 15, 2008 Author Share Posted October 15, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/#findComment-666076 Share on other sites More sharing options...
dennismonsewicz Posted October 15, 2008 Author Share Posted October 15, 2008 topic solved! I went back and reverted to using mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/128422-solved-different-excel-output-problem/#findComment-666145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.