[SOLVED] Return column names in SQL using PHP

This is a discussion on "[SOLVED] Return column names in SQL using PHP" within the Databases section. This forum, and the thread "[SOLVED] Return column names in SQL using PHP are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 20th, 2007, 23:04
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Return column names in SQL using PHP

Hi,

Is there any way to return an array containing the column names of a specific table??

Thanks,

Nathan.
Reply With Quote

  #2 (permalink)  
Old Dec 20th, 2007, 23:09
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Return column names in SQL using PHP

Code: Select all
SHOW COLUMNS FROM table_name
http://dev.mysql.com/doc/refman/5.0/...w-columns.html
Reply With Quote
  #3 (permalink)  
Old Dec 20th, 2007, 23:14
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Return column names in SQL using PHP

Hey, thanks for that. But if I use this query:

Code: Select all
  $sql = "SHOW COLUMNS FROM categories";
  $query = mysql_query($sql);
how do I now access this data??

Thanks,

Nathan.
Reply With Quote
  #4 (permalink)  
Old Dec 20th, 2007, 23:15
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Return column names in SQL using PHP

sorry, missed your link, will check that out
Reply With Quote
  #5 (permalink)  
Old Dec 20th, 2007, 23:21
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Return column names in SQL using PHP

Done.
thanks,

Nathan.
Reply With Quote
  #6 (permalink)  
Old Dec 20th, 2007, 23:32
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Return column names in SQL using PHP

Quote:
Originally Posted by nate2099 View Post
Hey, thanks for that. But if I use this query:

Code: Select all
  $sql = "SHOW COLUMNS FROM categories";
  $query = mysql_query($sql);
how do I now access this data??

Thanks,

Nathan.
Try
PHP: Select all

$sql "SHOW COLUMNS FROM categories";
  
$query mysql_query($sql);
$r mysql_fetch_assoc($query);
echo 
$r['COLUMNS']; 
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #7 (permalink)  
Old Dec 21st, 2007, 14:54
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Return column names in SQL using PHP

Hi Alex, for my purposes, and for anybody else who may find this thread..

Code: Select all
$result = mysql_list_tables(db_name);
  while ($row = mysql_fetch_row($result)) 
  {
echo $row[0];
}
Seemed to work to list all tables sequentually.

Thanks guys, as always a great help!!

Nate.
Reply With Quote
  #8 (permalink)  
Old Dec 21st, 2007, 14:57
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Return column names in SQL using PHP

Great, thanks for posting your result.
Want to mark this thread as solved now?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem with onsubmit="some_function();return false;" LumberJake JavaScript Forum 3 Mar 31st, 2008 15:00
[SOLVED] Column 'photo' cannot be null longstand PHP Forum 7 Dec 1st, 2007 15:08
ASP ADO Connection to return XML from SQL Proc NickyJ Classic ASP 2 Aug 11th, 2005 11:39
..copy data from column A in Table A to column B in Table B? gecastill Databases 10 Jun 23rd, 2005 18:27
return from db benbramz Classic ASP 5 Jun 19th, 2005 18:29


All times are GMT. The time now is 07:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43