I have the following script that dynamically creates table rows bases on the figure entered into the input field row_num.
(this happens in the first do while loop).
I want to then submit the resulting form results to a database.
Im having trouble getting the script to loop through each table row inserting a new table row into the database pending on the figure entered in the text field.
Hope Ive explained this clearley enough
<?php
echo "
<html>
<head>
<title>Aventis</title>
<link href='/aventis.css' rel='stylesheet' type='text/css'>
</head>
<body background='/gfx/reg/form_bgrnd.gif' bgproperties='fixed' class='scrollCol'>";
require "./config.inc.php";
$db_connect = mysql_connect ($host,$user,$passwd);
mysql_select_db($database, $db_connect);
$result = mysql_query("select * from rep where rep_username='$rep_username' AND rep_passwd='$rep_passwd'",$db_connect) or die ("cant do it");
// if username and password are matched
if ($row=mysql_fetch_array($result))
{
$name = $row['rep_f_name'];
$surname = $row['rep_s_name'];
$area = $row['area'];
echo
"
<table border='0' cellpadding='3' cellspacing='0'>
<tr>
<td class='txt' align='right'><b>Rep:</b></td><td class='txt'>$name $surname</td>
</tr>
<tr>
<td class='txt' align='right'><b>Area:</b></td><td class='txt'>$area</td>
<tr>
</table><br>
<table border='0' cellpadding'3' cellspacing'0'>
<tr>
<td>
<form method='post' action='$PHP_SELF?rep_username=$rep_username&rep_passwd=$rep_passwd'>
<input type='submit' class='submit' name='add_row' value='ROWS'>
<input type='text' class='select' name='row_num' size='3'>
</form>
</td>
</tr>
</table>
";
echo"
<form method='post' action='$PHP_SELF?rep_username=$rep_username&rep_passwd=$rep_passwd'>
<table width='100%' border='1' bordercolor='#999999' cellpadding='3' cellspacing='0'>
<tr>
<th>No.</th>
<th>Dr. Name</th>
<th>Speciality</th>
<th>Time Visit</th>
<th>Line</th>
<th>Prod 1</th>
</tr>";
// If form submit. Run the do while loop to create the desired number of rows
if ($add_row == "ROWS >")
$num = 0;
do
{
$num ++;
echo "
<tr>
<td align='center' class='txt'>$num</td>
<td align='center'>";
$sql = "SELECT * from physicians";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
echo "<select name='physisian' class='select'>";
while ($row = mysql_fetch_array($result))
{
echo "<option> " . $row['f_name'] . " " . $row['l_name'] . ", Code: " . $row['dr_code'] . "</option>";
}
echo "</select>";
echo "
</td>
<td align='center'>";
$sql = "SELECT * from speciality";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
echo "<select name='speciality$num' class='select'>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['speciality'] . "</option>";
}
echo "</select>";
echo "
</td>
<td align='center'>
<select name='time$num' class='select' class='select'>
<option>AM</option>
<option>PM</option>
</select>
</td>
<td align='center'>
<select name='line$num' class='select'>
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
<option>E</option>
</select>
</td>
<td align='center'>
<select name='sale_type$num' value='prod_option' class='select'>
<option>S</option>
<option>DA</option>
<option>GA</option>
</select>
</td>
</tr>";
} // end of do while loop!
while ($num < $row_num);
echo "
</table>
<table width='100%' border='0' cellpadding='3' cellspacing='0'>
<tr>
<td align='right'>
<input type='submit' class='submit' name='SEND' value='Send'>
</td>
</tr>
</table>
</form>
";
// If SUBMIT run do while loop and send the results to the database WHILE rows < $num
if ($SEND == "Send")
$rows = 0;
do
{
$rows ++;
$sql = mysql_query("INSERT INTO results SET
name = '$name'");
}
while ($rows < $num);
}
else
{
echo "no access";
}
echo "
</body>
</html>";
?>