suttercain Posted September 8, 2007 Share Posted September 8, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/68452-need-column-names-not-the-array-key/ Share on other sites More sharing options...
gerkintrigg Posted September 8, 2007 Share Posted September 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/68452-need-column-names-not-the-array-key/#findComment-344161 Share on other sites More sharing options...
Barand Posted September 8, 2007 Share Posted September 8, 2007 If you use mysql_fetch_assoc(), instead of mysql_fetch_row(), then the keys are the field names Quote Link to comment https://forums.phpfreaks.com/topic/68452-need-column-names-not-the-array-key/#findComment-344193 Share on other sites More sharing options...
sasa Posted September 8, 2007 Share Posted September 8, 2007 look http://www.phpfreaks.com/forums/index.php/topic,155530.0.html Quote Link to comment https://forums.phpfreaks.com/topic/68452-need-column-names-not-the-array-key/#findComment-344220 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.