Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old December 20th, 2007, 07:04 PM   #1
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
[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.
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 20th, 2007, 07:09 PM   #2
Highly Reputable Member
 

Join Date: Apr 2007
Location: Willich, Germany
Age: 22
Posts: 592
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough
Re: Return column names in SQL using PHP

Code:
SHOW COLUMNS FROM table_name
http://dev.mysql.com/doc/refman/5.0/...w-columns.html
c010depunkk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 20th, 2007, 07:14 PM   #3
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
Re: Return column names in SQL using PHP

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

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

Thanks,

Nathan.
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 20th, 2007, 07:15 PM   #4
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
Re: Return column names in SQL using PHP

sorry, missed your link, will check that out
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 20th, 2007, 07:21 PM   #5
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
Re: Return column names in SQL using PHP

Done.
thanks,

Nathan.
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 20th, 2007, 07:32 PM   #6
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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:
  $sql = "SHOW COLUMNS FROM categories";
  $query = mysql_query($sql);
how do I now access this data??

Thanks,

Nathan.
Try
Code:
$sql "SHOW COLUMNS FROM categories";
  
$query mysql_query($sql);
$r mysql_fetch_assoc($query);
echo 
$r['COLUMNS']; 
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 21st, 2007, 10:54 AM   #7
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
Re: Return column names in SQL using PHP

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

Code:
$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.
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old December 21st, 2007, 10:57 AM   #8
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: Return column names in SQL using PHP

Great, thanks for posting your result.
Want to mark this thread as solved now?
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 3 March 31st, 2008 11:00 AM
[SOLVED] Column 'photo' cannot be null longstand PHP 7 December 1st, 2007 11:08 AM
ASP ADO Connection to return XML from SQL Proc NickyJ Classic ASP 2 August 11th, 2005 07:39 AM
..copy data from column A in Table A to column B in Table B? gecastill Databases 10 June 23rd, 2005 02:27 PM
return from db benbramz Classic ASP 5 June 19th, 2005 02:29 PM


Search Engine Optimization by vBSEO 3.2.0 RC8