note 39496 deleted from function.mysql-num-fields by didou
| From: | didou@php.net | Date: | Fri, 30 Jan 2004 15:34:46 +0000 |
| Subject: | note 39496 deleted from function.mysql-num-fields by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-64439@lists.php.net to get a copy of this message | ||
Note Submitter: ian at bimmian point co point uk
----
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";
}