28, May 2012

query - first result is all column names - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  Databases
Topic: query - first result is all column names
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: query - first result is all column names  (Read 1812 times)
Community Supporter ?
Hunky Junky Monky Man!
**
Gender: Male
Posts: 68
436 credits
Members referred : 0


Schwa?


« on: Feb 09, 2008, 04:15:44 am »

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.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Feb 09, 2008, 08:16:28 am »

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++;
      }

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Feb 09, 2008, 11:03:29 am »

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.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Community Supporter ?
Hunky Junky Monky Man!
**
Gender: Male
Posts: 68
436 credits
Members referred : 0


Schwa?


« Reply #3 on: Feb 10, 2008, 03:30:12 am »

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!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7581
Tags : dynamic headers Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  Databases
Topic: query - first result is all column names
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 08:55:57 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.