I'm not sure if I got the terminology right, but what I want to do is get the names of fields within a table, so I can use them to generate an insert form for those fields.
I'm not sure what SQL you would need to use, as I'm still pretty inexperienced in it. I know there's a "show tables" command, is there something similar that I could use to retrieve field names?
Thanks.
Retrieving field names
there is a function mysql_list_fields. If you goto php.net and enter funtion names it gives docs and some samples. I found a good book at the beginning of my php experience was Professional PHP Programming published by Wrox. I still use this as a reference.
Best of luck,
losang
This is UNTESTED (ie off the top of my head) and is for postgresql...
this snippet should connect to your database and then put the names of all the
fileds in table tbl_foo into an array called $field_array. eg, if tbl_foo has
fields name 'name' 'address' and 'dob' then $field_array[0] should be "name",
$field_array[1] = "address" and so forth...
$db = pg_connect("", "", "", "", DATABASE);
$result = pg_exec($db, "select * from tbl_foo");
$listing_array = pg_fetch_array($result, 0);
while(list($key,) = each($listing_array))
$field_array[] = $$key;
pg_close($db);
then you should be able to do this:
print "enter $field_array[0] :";
print "<option type=\"text\" name\"$field_array[0]\">";
like i said, i haven't tested it, but it should work with only minimal tweaking.
frymaster
Thanks, for the function info and the book information. I've taken a look at that book before, and perhaps I will pick it up. Though I could just keep posting my questions here.
You can keep posting here but wouldn't you rather be the one who can answer the questions
good luck,
losang