pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris <dmagick@gmail.com>
To: Mag Gam <magawake@gmail.com>
Cc: pgsql-php@postgresql.org
Subject: Re: HTML FORMS selected question
Date: Mon, 04 Dec 2006 10:08:09 +1100
Message-ID: <457358D9.4000404@gmail.com> (raw)
In-Reply-To: <1cbd6f830612031442g23828ca7wad97fa4905aacc65@mail.gmail.com>
References: <1cbd6f830612031442g23828ca7wad97fa4905aacc65@mail.gmail.com>

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/



view thread (10+ messages)  latest in thread

Message-ID: <457358D9.4000404@gmail.com>
Permalink:  ../457358D9.4000404@gmail.com/
Also on:    postgresql.org/message-id/457358D9.4000404@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: dmagick@gmail.com, magawake@gmail.com
  Subject: Re: HTML FORMS selected question
  In-Reply-To: <457358D9.4000404@gmail.com>
  References: <1cbd6f830612031442g23828ca7wad97fa4905aacc65@mail.gmail.com> <457358D9.4000404@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox