|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Loop help
hi all can you help me with a loop
i have this form <form method="POST" action="makepreds.php?a=add_preds"> foreach ( $preds as $p) { <input type="text" name="matchid" value="'. $p['matchid'].'"> <input type="text" name="userid" value="'. $user['id'].'"> <input type="text" name="predtime" value="'.$p['predtime'].'"> } <input class="submit" type="SUBMIT" name="Predict" value="add"> and this : $preds_action = $_GET['a']; if ($preds_action == 'add_preds') { if (isset($_POST['Predict'])) { $insert_shout_query = mysql_query("INSERT ". $tbl_prefix ."predictiondata SET userid = '".$_POST['userid']."', pmatchid = '".$_POST['matchid']."', predtime ='".$_POST['predtime']."', "); } } but it only enter the last one in the form how do i loop it so it will enter all the input as the is 10 of each field... Thank you siriusdave... |
|
#2
|
|||
|
|||
|
Dave,
The way it is running now, you are going to end up with 10 fields of each, but all ten of each item will have the same name... So, even though there are 10 fields, the second one overwrites the first, then the third the second, and so on... If you want them to be 10 distinct fields, you need to add a value to the name... so the first time through the loop you would get matchid1, userid1, predtime1, then the second time, matchid2, userid2, predtime2, etc. I would probably add a counter to the loop, then use the counter to add the number to each field... You of course would then need to run the same counter on the insert query, so it will also run ten times, and insert each one of the "sets" of data. I hope that makes more sense to read than it did to type, Matt |
|
#3
|
|||
|
|||
|
yes it did but not sure what code i need for the couter and where to put it...
|
|
#4
|
|||
|
|||
|
Dave,
Something like this should work... Let me know, PHP Code:
|
|
#5
|
|||
|
|||
|
does not work ....
these are the whole files if it helps ..... makepeds.php PHP Code:
and makepreds.template.php PHP Code:
Last edited by siriusdave : May 7th, 2008 at 03:26 PM. |
|
#6
|
|||
|
|||
|
sorry to bump ...but anyone ?
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Loop help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|