Re: Quickform - looping through DB result set to create multiple records and radio buttons for each record

From: Date: Sun, 11 Dec 2005 01:34:46 +0000
Subject: Re: Quickform - looping through DB result set to create multiple records and radio buttons for each record
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22198@lists.php.net to get a copy of this message
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 =& $resultSet->fetchRow()) { > $ma[] =& $form->createElement > ('radio','type',null,'A','A'); > $ma[] =& $form->createElement > ('radio','type',null,'B','B'); > $ma[] =& $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 = array()) or set all 3 in the initialization: $ma = 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

« previous php.pear.general (#22198) next »