dennismonsewicz Posted October 10, 2008 Share Posted October 10, 2008 I have the folllowing code: <?php $field = mysql_num_fields($who_qry); while($row = mysql_fetch_assoc($who_qry)) { for($i = 3; $i < $field; $i++) { $names = mysql_field_name($who_qry, $i); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $title .= str_replace($numbers, '', ucwords($names . ',')); } } $excel=new ExcelWriter(); $explode = explode(',', $title); for($i = 0; $i < count($explode); $i++) { $pieces .= $explode[$i] . ','; } $trim = trim($pieces, ','); $myArr=array($trim); $excel->writeLine($myArr); ?> When it writes to the excel spreadsheet is placing all of the row names on one line i am guessing because the names are stored as one var instead of separate pieces of the array? Any ideas? Link to comment https://forums.phpfreaks.com/topic/127884-explode-for-array-help/ Share on other sites More sharing options...
dennismonsewicz Posted October 10, 2008 Author Share Posted October 10, 2008 bump Link to comment https://forums.phpfreaks.com/topic/127884-explode-for-array-help/#findComment-662171 Share on other sites More sharing options...
kenrbnsn Posted October 10, 2008 Share Posted October 10, 2008 What is this code supposed to do? Ken Link to comment https://forums.phpfreaks.com/topic/127884-explode-for-array-help/#findComment-662185 Share on other sites More sharing options...
Barand Posted October 10, 2008 Share Posted October 10, 2008 why all the moving from comma delimited strings to arrays and back again? And did you really want the column names repeating for every row? Anyway, try $who_qry = mysql_query ("SELECT * FROM user"); $field = mysql_num_fields($who_qry); while($row = mysql_fetch_assoc($who_qry)) { for($i = 3; $i < $field; $i++) { $names = mysql_field_name($who_qry, $i); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $title[] = str_replace($numbers, '', ucwords($names . ',')); } } $excel=new ExcelWriter(); foreach ($title as $t) { $excel->writeLine($t); } Link to comment https://forums.phpfreaks.com/topic/127884-explode-for-array-help/#findComment-662187 Share on other sites More sharing options...
dennismonsewicz Posted October 10, 2008 Author Share Posted October 10, 2008 now its not even printing the names updated code: $who_qry = mysql_query("SELECT * FROM has_had_projects")or die(mysql_error()); $field = mysql_num_fields($who_qry); while($row = mysql_fetch_assoc($who_qry)) { for($i = 3; $i < $field; $i++) { $names = mysql_field_name($who_qry, $i); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $title[] = str_replace($numbers, '', ucwords($names . ',')); } } $excel=new ExcelWriter(); foreach ($title as $t) { $excel->writeLine($t); } Link to comment https://forums.phpfreaks.com/topic/127884-explode-for-array-help/#findComment-662209 Share on other sites More sharing options...
Barand Posted October 10, 2008 Share Posted October 10, 2008 add echo statement $excel=new ExcelWriter(); foreach ($title as $t) { $excel->writeLine($t); echo "$t<br/>"; // print field name } I don't know your ExcelWriter class but does it need a filename? Link to comment https://forums.phpfreaks.com/topic/127884-explode-for-array-help/#findComment-662301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.