PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
my problem on this code is that i could not get the value of each textbox displayed on this loop.
why i try to save in database nothing will save. anyone can help me on this?, thanks in advance
//create form
<form name="aform" action="test.php" method="post">
//create table
<table border="2">
//create the row counter
<?php $numberofrow = 5;?>
//create the for loop
<?php for($counter = 1;$counter<=$numberofrow;$counter++){ ?>
//create 1 row for repeating
<tr>
//column 1 is to print out the counter for you to see.
<td><?php echo $counter; ?></td>
/*column 2 is a text field and the name is "textfield"+the value of the counter,
therefore they can have different names.*/
<td><input type="text" name="textfield<?php echo $counter;?>" /></td>
/*column 2 is a drop down menu and the name is "select"+the value of the counter,
therefore they can have different names.*/
<td><select name="select<?php echo $counter;?>">
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
</tr>
<?php }?>
//create the submit button
<tr><td><input type="submit" name="Submit" value="submit"/></td></tr>
</table>
</form>
my problem on this code is that i dont have fix number, it all depend on how many data from mysql table., i'll just used $numberofrow = 5 as a sample. and also my saving function is also in the same page, so i need to transfer those textbox value to a variable.
Ok just set $rows from $mysql_num_rows($query_result).
You'll also want to put somewhere in the form a hidden element with the number of rows so your handler knows how many rows are input (alternatively you could just loop until !isset($_POST['yourfield'+$increment) or something similar).
<?php
if (isset($_POST['number_rows']))
{
for ($i=0; $i<$_POST['number_rows']; $i++)
{
$textfield = $_POST['textfield'.$i];
$selectfield = $_POST['select'.$i];
// do whatever you want with $textfield and $selectfield which are the values for that value of $i
}
}
?>