how to retirieve field name

Discuss the development and implementation of Joomla! components here.
Locked
markedagain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 184
Joined: Tue Oct 10, 2006 5:05 pm
Location: Montreal
Contact:

how to retirieve field name

Post by markedagain » Tue Feb 13, 2007 3:15 pm

Hey guys,

i started creating a simple component(first one) and im wondering
if there is a function i can call to retrieve the field names of a table and manage to echo them using a for each loop?

M.

User avatar
davidwhthomas
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 247
Joined: Mon Sep 04, 2006 2:51 am
Location: New Zealand
Contact:

Re: how to retirieve field name

Post by davidwhthomas » Tue Feb 13, 2007 9:55 pm

Code: Select all

global $database;

$tables[] = '#__content'; //put table name here

$field_array = $database->getTableFields($tables); //get the field data

foreach($field_array as $field_data){ //loop through field data

	foreach($field_data as $field => $value){ 

	   print "Field: ".$field. "<br />"; //echo the field name

	}

}
Last edited by davidwhthomas on Tue Feb 13, 2007 10:09 pm, edited 1 time in total.

markedagain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 184
Joined: Tue Oct 10, 2006 5:05 pm
Location: Montreal
Contact:

Re: how to retirieve field name

Post by markedagain » Mon Feb 19, 2007 2:45 pm

sweet, thx so much dave.

following up on your answer i posted another question in the dev forum, maybe you might be able to assist me there also.

thank you very much.

http://forum.joomla.org/index.php/topic,142610.0.html

MAtkins
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Wed Apr 11, 2012 7:22 pm

Re: how to retirieve field name

Post by MAtkins » Mon Dec 02, 2013 8:54 pm

davidwhthomas:
Thank You!! I've been looking for this for hours and here you are with the answer.

I tried what looks like the same code but I must have had something wrong.
I think I didn't realize that the param in getTableFields is an array.
The docs are unclear about it.

Works now! Thanks again.


Locked

Return to “Components”