note 29682 added to function.mysql-field-name

From: Date: Fri, 21 Feb 2003 12:27:57 +0000
Subject: note 29682 added to function.mysql-field-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-44306@lists.php.net to get a copy of this message
You could probably elaborate on this by sending a full sql query to this function...but I titled it simple_query() because it doesn't really allow for joins. Never the less, if you want to get a quick array full of a single row result set this is painless: function simple_query($table_name, $key_col, $key_val) { // open the db $db_link = my_sql_link(); // query table using key col/val $db_rs = mysql_query("SELECT * FROM $table_name WHERE $key_col = $key_val", $db_link); $num_fields = mysql_num_fields($db_rs); if ($num_fields) { // first (and only) row $row = mysql_fetch_assoc($db_rs); // load up array for ($i = 0; $i < $num_fields; $i++) { $simple_q[mysql_field_name($db_rs, $i)] = $row[mysql_field_name($db_rs, $i)]; } // and return return $simple_q; } else { // no rows return false; } mysql_free_result($db_rs); } **Please note that my_sql_link() is just a function I have to open up a my sql connection.** -- http://www.php.net/manual/en/function.mysql-field-name.php http://master.php.net/manage/user-notes.php?action=edit+29682 http://master.php.net/manage/user-notes.php?action=delete+29682 http://master.php.net/manage/user-notes.php?action=reject+29682

« previous php.notes (#44306) next »