Re: Creating Arrays
| From: | Ashley M. Kirchner | Date: | Wed, 11 Apr 2001 21:55:38 +0000 |
| Subject: | Re: Creating Arrays | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48208@lists.php.net to get a copy of this message | ||
"Rodney J. Woodruff" wrote:
> http://www.php.net/manual/en/function.msql-fetch-array.php
Okay, call me dense. I can't figure this out. This is what I'm trying to
do:
$sql = "select p_id, project from proj where uid=$uid";
$result = mysql_db_query($database,$sql);
(the resulting table in mysql is as follows:
+------+-----------+
| p_id | project |
+------+-----------+
| 0 | Undefined |
| 1 | Work |
| 2 | Personal |
+------+-----------+
3 rows in set (0.00 sec)
...yes, that 'Undefined' IS a valid project, and the p_id's don't
necessarily start at 0 either.)
I need that result into the following:
$items = array(0 => "Undefined", 1 => "Work", 2 =>
"Personal");
Reason is, I pass that $items variable to the following function:
function MakeSelect($items, $selected) {
$str = "";
while(list($value, $name) = each($items)) {
$str .= "<option value=\"$value\"" . ($value != $selected ? \
">" : " selected>") . "$name\n";
}
return $str;
}
...which then creates (assuming the person had 'Work' previously
selected):
<select name=whatever_i_specify>
<option value="0">Undefined
<option value="1" selected>Work
<option value="2">Personal
</select>
How do I create that $items array?
AMK4
--
W |
| I haven't lost my mind; it's backed up on tape somewhere.
|____________________________________________________________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ashley M. Kirchner <mailto:ashley@pcraft.com> .
303.442.6410 x130
SysAdmin / Websmith . 800.441.3873 x130
Photo Craft Laboratories, Inc. . eFax 248.671.0909
http://www.pcraft.com . 3550 Arapahoe
Ave #6
.................. . . . . Boulder, CO 80303, USA