PHP Loop question

Soldato
Joined
25 Jan 2003
Posts
11,542
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?
 
Code:
while ($i < 10) {
print '<tr><td><input type=\"text\" name=\"txt".$i".\" /></td></tr>';

Should do it I think im a little rusty. Should name them txt1,txt2 etc.

edit: son of a ... :rolleyes: :D
 
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:
Ripper^ said:
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?

If you have a selection for the number boxs you must have a form with some kind list box on. You need to set each value in the list box to the correct number then get this value on your next script that constructs this page.
 
Back
Top Bottom