Re: Creating Arrays
| From: | Rodney J. Woodruff | Date: | Thu, 12 Apr 2001 13:48:11 +0000 |
| Subject: | Re: Creating Arrays | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48299@lists.php.net to get a copy of this message | ||
Do you understand the options that the other people have explained?
-- Rodney
"Ashley M. Kirchner" wrote:
> "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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net