Jump to content

explode, for, array help


dennismonsewicz

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.