note 39497 added to function.mysql-field-name
| From: | php-general at lists dot php dot net | Date: | Fri, 30 Jan 2004 15:19:31 +0000 |
| Subject: | note 39497 added to function.mysql-field-name | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64437@lists.php.net to get a copy of this message | ||
This is a little script that i wrote up that i hope you may find useful. Essentially, it will
connect to your database/table, retrieve a single record based on the WHERE portion of the SELECT
command.
It will then take all of the data from that record, and put the data into variables that are named
the same as the field that the actual data is located in.
It also prints out what it has retrieved and what it has stored in each variable name. To remove
this debugging feature, remove the ECHO line
if you wanted to work with a couple of records at once, this code is set up to store all retrieved
data from the record into an array called $data, where info can be recalled by using the variable
$data[fieldname]
$db = mysql_connect ("","","");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM serviceform WHERE rec='1'");
$row = mysql_fetch_row($result);
for ($i = 0; $i < mysql_num_fields($result); $i++) {
$field = mysql_field_name($result, $i);
$contents = $row[$i];
$data[$field] = $contents;
print "$field = $contents<br>\n";
}
----
Manual Page -- http://www.php.net/manual/en/function.mysql-field-name.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39497
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39497&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39497&report=yes
Search -- http://master.php.net/manage/user-notes.php