For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > December 2005 > Re: [PEAR] Quickform - looping through DB result set to create multiple records and r









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] Quickform - looping through DB result set to create multiple records and r
Justin Patrin

2005-12-10, 10:09 pm

On 12/10/05, l Burnerheimerton <lburnerheimerton@yahoo.com> wrote:
> I get a result set form DB of names($row[1]) and a ID
> field($row[0]).
>
> With this, I loop through the result set and create a
> form element and radio button for each. Like:
>
> while ($row =3D& $resultSet->fetchRow()) {
> $ma[] =3D& $form->createElement
> ('radio','type',null,'A','A');
> $ma[] =3D& $form->createElement
> ('radio','type',null,'B','B');
> $ma[] =3D& $form->createElement
> ('radio','type',null,'C','C');
> $form->addGroup ( $ma, 'radio'.$row[0], $row[1].' :'
> );
> }
>
> The problem is that it continually uses $ma for each
> different record and adds three new radios to each new
> record - not good.


Ummm...that's because you're not initializing it. Of course it's
adding new radios to the array every time. Either initialize it inside
the loop ($ma =3D array()) or set all 3 in the initialization:
$ma =3D array(HTML_QuickForm::createElement(...),
HTML_QuickForm::createElement(...),
....);

>
> I need to figure out a way dynamically change the
> variable name, $ma, to $ma.$row[0] or something like
> that.
>
> I tried $ma.$row[0] and it throws error:
> Parse error: parse error, unexpected '['
>
> Any ideas how to accomplish this?
>


Just use an array of arrays $ma[$num][0], etc.

--
Justin Patrin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com