note 59857 deleted from function.mysql-query by philip

From: Date: Fri, 04 Sep 2015 19:20:18 +0000
Subject: note 59857 deleted from function.mysql-query by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203646@lists.php.net to get a copy of this message
Note Submitter: Harmor ---- Modification of hipsurgery submission. Here's a utility function that will return an array of a table. Don't forget to connect to the DB before calling this function. <?php //Returns an array[columnName] = value of a $table_name function table_to_array($table_name) { $columns = array(); $result_all= mysql_query("SELECT * FROM $table_name"); $result_columns = mysql_query("SHOW COLUMNS FROM $table_name"); //get the columns from the table into $colums[] while ($columnRow = mysql_fetch_array($result_columns, MYSQL_ASSOC)) { $columns[] = $columnRow } while ($data = mysql_fetch_assoc($result_all, MYSQL_ASSOC)) { foreach ($columns as $column_name) { $array[$column_name] = $data[$column_name]; } } return $array; } ?>

« previous php.notes (#203646) next »