This question is solved. Code is below.
Currently I have a piece of code that is something like this:
while ($query…) {
<checkbox form named "rating"> <submit button for "rating">
}
All that, x20. The x20 is determined by the variable $rpp (results per page. It’s not shown in the code, since it’s irrelevant to the question). Each form has their individual “submit” button.
What I want to achieve is, I want to give checkbox and radio button all individual names, so instead of what I have now, I can have the submit button outside the while-loop, meaning, there is only ONE submit button for all x20 checkbox/radio button forms.
E.G checkbox_0, checkbox_1,…
My only question is, how do I achieve this? And where do I play my submit button? Am I asking the right questions too? I apologize if I am sounding a bit vague. If you have a question, please ask, I will answer it.
I gave it a try in my code below. It seems it’s not a practice many people do, so most of my Googling did not turn up anything too useful, though I do have an idea of where to start. Could someone give me some guidance?
<?
if (isset($_POST['formSubmit'])){
$j = 1;
while ($j < $_GET['rpp']) {
$rating = mysql_real_escape_string($_POST['rating'.$j]);
$accountID = $_POST['accountID'.$j];
mysql_query("UPDATE Spreadsheet SET rating='$rating' WHERE accountID='$accountID'");
$j++;
}
}
$k = 1; ?>
<form name ="rating" method ="POST" action ="" > <?
while($row = mysql_fetch_array($query)){
// Drop-down menu
$values = array('0 - No rating','1 - Very Bad','2 - Bad','3 - Average','4 - Above Average');
echo "<input type = \"hidden\" name = \"accountID" . $k . "\" value = \"" . $row['accountID'] . "\" >";
for($i = 0; $i < count($values); $i++){ ?>
<input type="radio" name="rating<? echo $k; ?>" value="<?php echo $values[$i]; ?>" id="rbl_0" <? if($row['rating'] == $i) echo "checked='checked'"; ?>/>
<? echo $values[$i] ?> <br> <?
}
$k++;
} ?>
<input type ="Submit" name ="formSubmit" value ="Submit and Next Page" />
</form> <?
EDIT: The output of this code at the moment shows individual submit buttons for each form field. What I would like to achieve is to have one submit button for all the form-fields.
EDIT 2: Figured it out! Final edit is how I did it. For others who may stumble on this question in the future.
Try this: you want to move your form declaration outside of your while loop. Which also means that you want to move your submit button outside your while loop. Everything inside can stay the same because your radio buttons have unique names per while loop iteration and are grouped per for loop iteration.