Jump to content

Recommended Posts

Hi guys,

 

I am running a script that exports a MySQL table into an excel file. The problem I am having is the column (header) names are not showing up in the final .xls file. I instead get the key value 0, 1, 2, etc.

 

Here is the section of the code that should write the actual names. I can't figure out what's wrong. It looks good to me. Am I missing something?

 

$query_string = "select * from $tablename";
$result_id = mysql_query($query_string, $connection);
$column_count = mysql_num_fields($result_id);



while ($row = mysql_fetch_row($result_id))
{
	// The folowing if/then statement prints out the column names.
	if(!$dokeys){
		$keys = array($row);
		foreach($keys as $key){
			$data .= $key . "\t";
		}
		$dokeys = true;
	}

Link to comment
https://forums.phpfreaks.com/topic/68452-need-column-names-not-the-array-key/
Share on other sites

I saw that this was a problem before actually...

There is a way around it on Google somewhere.

 

A few moments poking around: http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Databases/Q_21327293.html

 

You'll need to sign up and there's no guarantee that their solution works but hey ho...

 

i had the same problem and think that there MAY be a tutorial on it somewhere around one of the freaks' websites.... as MySQL Freaks appears to have been removed, it might have been moved here.

 

Have a look.

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.