PDA

View Full Version : help with for loop on data from form...


sir pannels
01-10-2003, 02:12 AM
hey,
ok im a bit stuck here.. im not to good with loops and dont really know how im gona do this....
i have a page that calls some info from a db... it calls all the rows under the specified ID, and adds a hidden text field to each, if the users hits a form button these rows with their hidden text fields get send to a script that needs to do a calculation...the calculation i have done...
its simply something like..
$answ1 = $val1 * $hiddenfield
$answ2 = $answ1 + 50
$finalans = $answ2 * 3
the bit im stuck on is how to make it do that for every row(with its hidden txt field val) until there are no more rows.
i hope this makes sense i think i exsplsained badly.
anyhows.. is anyone able to help me with this?
thanks:thumbsup:
-P-:cool:

SYP}{ER
01-10-2003, 02:31 AM
You did explain poorly, but I'll just give you this bit of info in case you don't know it:

If you name a set of form fields like so:

<input type="hidden" name="vals[]" />
<input type="hidden" name="vals[]" />
<input type="hidden" name="vals[]" />
<input type="hidden" name="vals[]" />
<input type="hidden" name="vals[]" />

The values are put into an array automatically by PHP when the form is submitted, meaning you can do like so:

foreach ($vals as $val){
echo $val."<br />";
}

To echo the value of each form field entered :)

I tell you this because it seems you want to just take some fields and do something to each of them, but the problem is that you don't know how many there may be. So this should help...

sir pannels
01-10-2003, 02:41 AM
thanks that is helpfull.
tho one more thing.. how do ii alter the ($val as $val) part so that it can recive 2 values... i forgot to say there is a normal text imput that will hold a number aswell as the hidden.. sorry *duh*
thanks Aaron :D

SYP}{ER
01-10-2003, 11:57 AM
Ah, that would be easier with a for() loop:

for ($i=0;$i<count($vals);$i++){
echo $vals[$i]."<br />".$vals2[$i]."<br /><br />";
}

Where $vals is the first set of fields (name="vals[]") and $vals2 is the second set of fields (name="vals2[]").

:)