Assuming a recent release of MySQL:
open the schema information_schema then

select TABLE_NAME, COLUMN_NAME from COLUMNS where TABLE_NAME = '$table';

Steve

On Wed, Apr 16, 2008 at 10:55 AM, Richard Heyes <[EMAIL PROTECTED]>
wrote:

> 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!
> >
>
> I would prefer hard (or soft) cash... :-)
>
>  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...
> >
> > Am I on the right path? Way off base? Not even in the ball park?
> >
> > Hopefully it makes sense... Cause it's right on the edge of my knowledge
> > so I'm not totally sure how to ask it right yet :)
> >
>
> You could do it adequately with a DESCRIBE, but there might be something
> that's "better". I would suggest looking through the code of my TableEditor:
>
> http://www.phpguru.org/static/TableEditor.html
>
> --
> Richard Heyes
> Employ me:
> http://www.phpguru.org/cv
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
There is no greater gift to an insecure leader that quite matches a vague
enemy who can be used to whip up fear and hatred among the population.
-Paul Rusesabagina, humanitarian (b. 1954)

Human beings are perhaps never more frightening than when they are
convinced beyond doubt that they are right. -Laurens van der Post, explorer
and writer (1906-1996)

Reply via email to