miocene Posted July 22, 2009 Report Share Posted July 22, 2009 I have made a script that generates an html form based on the number of users in a table...Here is the code: <form action="addpayment.php" method="post" name="addpayment">Company Name: <input name="company" type="text" /> <br />Item Purchased: <input name="item" type="text" /> <br /> <br />How much did each person pay?<br /> <?phpinclude("selectusers.php"); for ($k=0; $k<=$num_users - 1; $k++) {echo $users[$k] . " paid: £ <input name=\"" . "person" . ($k+1) . "paid" . "\" type=\"text\" /> <br />";}<br /><input type="submit" value="Submit" /></form> $users is an array containing all the names of the users in table$num_users is an integerLater on I will want variables that say how much each user has paid and how much they oweE.g. $person1_paid and $person1_topayThese variables will need to be created based on the number of fields in the form as the input names of the text boxes will go:person1paidperson2paidperson3paidetcso I will need some code that goes like for ($i=1; $i<=$num_users; $i++){$person"$i"paid = $POST['person"$i"paid'];} where "$i" is the variable $i as a string Link to comment Share on other sites More sharing options...
Synook Posted July 22, 2009 Report Share Posted July 22, 2009 for ($i=1; $i<=$num_users; $i++) { $person[$i]['paid'] = $POST["person{$i}paid"]; $person[$i]['topay'] = $POST["person{$i}topay"];} ? Link to comment Share on other sites More sharing options...
miocene Posted July 22, 2009 Author Report Share Posted July 22, 2009 for ($i=1; $i<=$num_users; $i++) { $person[$i]['paid'] = $POST["person{$i}paid"]; $person[$i]['topay'] = $POST["person{$i}topay"];} ? Thanks I think I figured out a simpler way...check at my testing site Link to comment Share on other sites More sharing options...
Synook Posted July 22, 2009 Report Share Posted July 22, 2009 I can't see the source, but if it works, why not? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now