Jump to content

Html And Loops...


badrobot
 Share

Recommended Posts

I am using an html form and looping it with a scripting language but i want some of the "html variables" to change each time it loops....for example here is a form...

<input type="text" name="acctnum"><input type="text" name="itemnum"><input type="text" name="qtynum"><input type="submit" name="submit" value="submit">

I want to wrap the 2 of the lines in a loop so that it will only loop 2 parts of the form. So I use a scripting language (php) and make the loop.

<input type="text" name="acctnum"><?phpdo {$i++;?><input type="text" name="itemnum"><input type="text" name="qtynum"><?php}while($i<51)?><input type="submit" name="submit" value="submit">

How can I change the variables "itemnum" and "qtynum" each time it loops? shouldnt there be someway for me to drop the $i variable into the name="" field somehow? that way it will have 1 then 2 then 3 added to the name each time it cycles through the loop?

Link to comment
Share on other sites

<?php   for ($i = 0; $i < 50; $i++) {	  echo "<input type='text' name='itemnum$i'>";	  echo "<input type='text' name='qtynum$i'>";   }?>

Having the whole string in double quotes makes sure $i gets interpolated. So I replaced your html double quotes with singles. You could make them doubles if you escaped them, but really, who'd care?

Link to comment
Share on other sites

<?php   for ($i = 0; $i < 50; $i++) {	  echo "<input type='text' name='itemnum$i'>";	  echo "<input type='text' name='qtynum$i'>";   }?>

Having the whole string in double quotes makes sure $i gets interpolated. So I replaced your html double quotes with singles. You could make them doubles if you escaped them, but really, who'd care?

AH there we go I thought it was kind of dumb for me to have to end the php segment before i used html... I'll try it and report back /salute
 ?>

PS: I laughed when I read your sig because I'm re-doing a website right know and the original author could have used your list...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...