Re: Re: Form Loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2008-10-19 at 09:31 -0500, Shawn McKenzie wrote:
> Rick Pasotto wrote:
> > On Sat, Oct 18, 2008 at 08:07:26PM -0500, Shawn McKenzie wrote:
> >> Terry J Daichendt wrote:
> >>> I'm trying to create a form with a loop. I need to append a value to a
> >>> field name each time through the loop. For Instance:
> >>>
> >>> while ($row = mysql_fetch_assoc($result)) {
> >>>     $x=1;
> >>>     echo "<tr>";    echo "<td><input type='text' id='qty'
> >>> name='quantity_'  size='2' value='$row[qty]' /></td>";
> >>>     echo "</tr>";
> >>>     $x++;
> >>> }
> >>>
> >>> the name value quantity needs the value of x appended to it. quantity_1,
> >>> quantity_2 etc. What is the correct syntax to achieve this, especially
> >>> the parsing to get it to work. I suspect the dot operator to append it
> >>> but I can't get the parsing down.
> >>>
> >>> Terry Daichendt
> >> echo '<td><input type="text" id="qty" name="quantity_' . $x . '"
> >> size="2" value="' . $row['qty']. '" /></td>';
> >>
> >> However, I would use an array:
> >>
> >> echo '<td><input type="text" id="qty" name="quantity[' . $x . ']"
> >> size="2" value="' . $row['qty']. '" /></td>';
> >>
> >> Depending upon your use, you can even leave out the index and let it
> >> increment.
> >>
> >> echo '<td><input type="text" id="qty" name="quantity[]" size="2"
> >> value="' . $row['qty']. '" /></td>';
> > 
> > Ids must be unique within a document.
> > 
> Yeah, I just copied and pasted and was concentrating on the name.
> 
> echo '<td><input type="text" id="qty' . $x . '" name="quantity[]"
> size="2" value="' . $row['qty']. '" /></td>';
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com
> 
Take out the id attribute on the input element though, as these must be
unique for an element, and the only reason to use them in this case
would be if you had label tags giving the input boxes a name.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux