note 39497 deleted from function.mysql-field-name by didou

From: Date: Fri, 30 Jan 2004 15:34:51 +0000
Subject: note 39497 deleted from function.mysql-field-name by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64440@lists.php.net to get a copy of this message
Note Submitter: ---- 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"; }

« previous php.notes (#64440) next »