Sublime directory Surf the web anonymous Pagerank Monitor


query - first result is all column names

aaron_s
Sat 9 February 2008, 04:15 am GMT +0100
Lets say you have a 3 column database with colums of 'id', 'username' and 'registrationDate'

So lets say you want to generate a csv with somethignl ike mysql, you can.... but lets put the column names on the top.  Cool


Select 'id', 'username', 'registrationDate'
union
Select * from tableName;

coolios. 


Now here's the thing - how would you make it be a dynamic thing?    I don't want to modify this particular query whenever I add a new column.


(If you ask why - go for it - I'll explain - but I don't think its needed for the solution.)

Any ideas are more than welcome.

olaf
Sat 9 February 2008, 08:16 am GMT +0100
is ity this what you mean:

$result = mysql_query(sprintf("SELECT * FROM %s", $this->table));
$i = 0;
while ($i < mysql_num_fields($result)) {
$type  = mysql_field_type($result, $i);
    $name  = mysql_field_name($result, $i);
$this->table_fields[$name] = $type;
$i++;
}

Nikolas
Sat 9 February 2008, 11:03 am GMT +0100
You can do what you want with 2 queries. The one is this :

SHOW COLUMNS FROM `table`

Then get the `Field` field from that table, and then call a

SELECT * FROM `table`

to fetch all the data.

aaron_s
Sun 10 February 2008, 03:30 am GMT +0100
Let me clear it up - it all has to be written as a SQL script or a set of them that can be ran into the mysql CLI.

So - olaf: no access to PHP
Nikolas: show columns shows the columns with descriptive data in rows.  I need the results in one row - multiple columns.

Thanks!

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional