PHP Loop question

Soldato
Joined
25 Jan 2003
Posts
11,550
Location
Newark, Notts
I've got a loop which outputs a number if text boxes depending on user selection. Everything works as it should but how can I get it to name each textbox it creates differently? Here's a snippet from the section of the loop i'm talking about:

Code:
while ($i < 10) {
print '<tr><td><input type="text" name="txt1" /></td></tr>';

Obviously at the moment every textbox created will be called "txt1". But i want each subsequent one to have a different name from the last, ie txt2 txt3 etc. How would I go about achieving this?
 
One last thing. I have a select menu so that the user selects how many inputs they want to appear (1-10), yet when 1 is selected, 10 appear, and vice versa. What do i need to change in the while loop to make it work properly?
 
Code:
while ($i <= 10 && $i > 0) {

and $i = whatever the user selects from the menu (1-10)
 
Last edited:
Back
Top Bottom