Jump to content

Html And Loops...


badrobot

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...