note 59857 added to function.mysql-query
| From: | Harmor at osu1 dot php dot net | Date: | Sun, 18 Dec 2005 13:32:25 +0000 |
| Subject: | note 59857 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100372@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59857
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59857&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59857&report=yes
Search -- http://master.php.net/manage/user-notes.php