Re: HTML FORMS selected question - Mailing list pgsql-php

From Chris
Subject Re: HTML FORMS selected question
Date
Msg-id 457358D9.4000404@gmail.com
Whole thread Raw
In response to HTML FORMS selected question  ("Mag Gam" <magawake@gmail.com>)
Responses Re: HTML FORMS selected question  ("Randy Moller" <zoomerz@comcast.net>)
List pgsql-php
Mag Gam wrote:
> I am having trouble getting values populated in my form... Here is what
> I got so far:
>
> //The values that need to be selected
> $result_ip=pg_query($dbconn,$test_query);
>
> <SELECT    NAME="ip[]" SIZE=10 MULTIPLE>
> <?php
> //This will show ALL values.
> while($rows=pg_fetch_array($result)){
> foreach ($options as $index => $option) {
>     if ($rows[1]==$option)
>     {


What does $rows contain? What does $options contain?

You could also simplify this a little bit. I'd at least remove the
foreach $options loop and use "in_array" - see php.net/in_array

while ($rows = pg_fetch_array($result)) {
   $selected = '';
   if (in_array($rows[1], $options)) {
     $selected = ' SELECTED';
   }
   sprintf('<option value="%s"%s>%s</option>', $rows[1], $selected,
$rows[1]);
}

--
Postgresql & php tutorials
http://www.designmagick.com/

pgsql-php by date:

Previous
From: "Mag Gam"
Date:
Subject: HTML FORMS selected question
Next
From: Chris
Date:
Subject: Re: HTML FORMS selected question