Re: [solution] QuickForm_advmultiselect - can you open the form with the SELECTED list already populated from a data set?
| From: | l Burnerheimerton | Date: | Tue, 30 Aug 2005 17:41:38 +0000 |
| Subject: | Re: [solution] QuickForm_advmultiselect - can you open the form with the SELECTED list already populated from a data set? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20673@lists.php.net to get a copy of this message | ||
--- Laurent Laville <pear@laurent-laville.org> wrote:
> l Burnerheimerton wrote:
> >
> > I appreciate your help. Here what I have that is
> > still not working. It's giving the same issue as
> > before - the selected list has one blank entry
> that
> > you can move to available list. Any help is
> greatly
> > appreciated!
> >
> > $form = new HTML_QuickForm('amsCustom1');
> > $form->removeAttribute('name'); // XHTML
> compliance
> >
> > $all_people = $db->getAssoc("SELECT ...");
> > $selected_people = $db->getAssoc("SELECT ...");
> >
> > $form->setDefaults(array( //set form field
> defaults
> > 'people' => $selected_people)
> > );
>
> Nice study case, it will increase my FAQ section.
>
> I've reproduced your problem and found orign.
>
> your AVAILABLE array is associative array with key
> => value
> while your SELECTED array should be only a key list
>
> for example, if in your script you have data sets
> like this:
>
> $all_people = array(
> 'farell' => 'laurent laville',
> 'mj' => 'martin jansen',
> 'cellog' => 'greg beaver' );
> AND
> $selected_people = array('farell');
>
> will works fine
>
> BUT
> $selected_people = array('farell' => 'laurent
> laville');
>
> will produce a such blank line
>
> So i suggest to retrieve only the row KEYs from your
> database
> for the SELECTED array
>
> Hope i'm clear
>
> Regards
> Laurent
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
I'm not sure how to do this using Pear DB: I've tried
the following three methods to get what you said I
needed and it still gives my the blank entry in the
selected column:
$selected_people = $db->getCol("SELECT
CONCAT(lastName, \", \", firstName) FROM people WHERE
ID = 17");
$selected_people = $db->getOne("SELECT
CONCAT(lastName, \", \", firstName) FROM people WHERE
ID = 17");
$selected_people = $db->query("SELECT CONCAT(lastName,
\", \", firstName) FROM people WHERE ID = 17");
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs