Re: using a variable as values in an array
| From: | Charles Kline | Date: | Mon, 31 Mar 2003 22:12:20 +0000 |
| Subject: | Re: using a variable as values in an array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26764@lists.php.net to get a copy of this message | ||
Hmm... that is not quite it. Here is a better example:
Here is how I would define default values for a checkbox in HTML_QuickForm;
$defaultValues['ichkABC'] = array('A'=>true,'B'=>true);
$form->setDefaults($defaultValues);
The checkboxes are defined later like this:
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null, 'A');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null, 'B');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null, 'C');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'D', null, 'D');
$form->addGroup($checkbox, 'ichkABC', 'ABCD:', array(' ', '<br />'));
So what I am trying to do is built that array that gets passed to: $defaultValues['ichkABC'] =
If I can create a variable that contains the array that is fine too. the values 'A' or 'B' as in the above example will be the values in quotes as I get them from my table query.
thanks
charles
On Monday, March 31, 2003, at 04:52 PM, Jennifer Goodie wrote:
$mystring; foreach ($sth_opt as $thekey => $thevalue){ $mystring .= "'".$thevalue."'=>true, "; } $defaultValues['ib_article'] = array($mystring);Try this ... foreach ($sth_opt as $thekey => $thevalue){ $defaultValues['ib_article'][$thevalue] = 'true'; } I'm not sure if the indices line up exactly with what you had in mind, but I'm confident you can play with it to get what you want. -----Original Message----- From: Charles Kline [mailto:ckline@rightcode.net] Sent: Monday, March 31, 2003 1:49 PM To: Jennifer Goodie Cc: php-db@lists.php.net Subject: Re: [PHP-DB] using a variable as values in an array Here is more details. Thanks for the reply. I am using HTML_QuickForm (pear) to create my forms. In order to set the default state of some of the elements (checkboxes in this case) I need to pass an array as the value to QuickForm. This array needs to be in the format of this: array('30'=>true, '29'=>true) where the 30 and 29 are the values that are coming back from my query. This could return up to 50 records. This is what I was trying, but it isn't woring: $mystring; foreach ($sth_opt as $thekey => $thevalue){ $mystring .= "'".$thevalue."'=>true, "; } On Monday, March 31, 2003, at 04:32 PM, Jennifer Goodie wrote:Instead of building a string in your loop do the assignment in the loop I have no idea what is being pulled from where, so I can't really give a good example -----Original Message----- From: Charles Kline [mailto:ckline@rightcode.net] Sent: Monday, March 31, 2003 1:25 PM To: php-db@lists.php.net Subject: [PHP-DB] using a variable as values in an array I am trying to build an array from the results of a query on a mySQL table. I am using a loop to create this string in a variable $mystring: '30'=>true, '20'=>true I then need to use it like this: $defaultValues['ib_article'] = array($mystring); It isn't working. I am sure there is a better method, can anyone point me in the right direction? thanks charles -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php