Jason Pruim wrote:

On Apr 16, 2008, at 5:37 PM, Chris wrote:

Jason Pruim wrote:
Hi Everyone!
I'm back with yet another question.... But getting closer to sounding like I know what I'm talking about and that's all thanks to all of you. A free beer (Or beverage of choice)* for everyone who has helped me over the years! Here's my question... I have a program, where I want to take out the field names in a database table and display them... In other words instead of writing:
$Query ="SELECT First, Last, Middle, Add1 FROM mytable order by $order";
I want to write something more like:
$Query ="SELECT $FIELDNAMES FROM mytable order by $order";
So I need to know how to get the field names from the database so that I can populate $FIELDNAMES. I played a little bit and it looks like I might be able to get what I want by doing 2 queries...
$QueryFieldNames = "DESCRIBE $table";
And then some sort of a foreach or maybe a while to populate $FIELDNAMES? Maybe an array so I could do $FIELDNAMES['First'] if I needed to later. then I can use my SELECT $FIELDNAMES FROM $table order by $order query to do my query...

If $FIELDNAMES contains all the fields, I have to ask why?

What I am trying to accomplish is a customer wants me to add custom fields to their table in my database, I want to use the same code to display the separate fields... In other words right now I have the field names hard coded into my app.. I want to be able to remove the actual field names and have them pulled dynamically from the database, so it doesn't matter if there is 10 fields or 30 fields, it will print a header row that contains ALL the field names and format the table properly.

Sure - but you can do it all in one go.

Another approach (which is database independent) is

select * from table limit 0;


Had to throw that in the mix :)

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to