|
-
Feb 2nd, 2003, 08:59 AM
#1
Thread Starter
Fanatic Member
put table field names into an array
I am using PHP with a MySQL database.
I am wondering if it's possible to get the field names of a table dynamically and put them into an array? I would also be nice to dynamically get a list of tables in the database also. So if a table is added or a field is added I don't have to change my code.
In VBScript you can do a recordset(iFieldPosition).Name and get the name of the field.
Currently the only why I have seen in php is to hardcode the field name you want to work with. Example:
while ($row = mysql_fetch_array($sql_result)) {
$variable1 = $row["FIELD1"];
$variable2 = $row["FIELD2"];
}
Thanks in advance for your help.
-
Feb 2nd, 2003, 12:45 PM
#2
Stuck in the 80s
It'd do you wonders to check out the manual at www.php.netwww.php.net, specifically http://www.php.net/manual/en/ref.mysql.php.
Check out these functions mysql_list_fields(), mysql_list_tables(), and mysql_list_dbs().
-
Feb 2nd, 2003, 01:57 PM
#3
Frenzied Member
yes you can. to get the tables it is
mysql_table_list() I believe, then you have to search for the field names.
$local_query = "SHOW FIELDS FROM " . $table);
jsu tlike that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|