I don't exactly understand your code, it seems you have left out
some code needed for me to understand more. Is this for an html form or what?
I think your problem of only the first record displayed is in your
while loop. You loop once and create a combo box with the first
record
For an html form here is what I might suggest:
I prefer to use the $HTTP_POST_VARS array to retrieve data
posted from a form instead of $PHP_SELF, i think it is easier
to get and manipulate the form element data posted.
$HTTP_POST_VARS array is an array that contains key->value
pairs of all elements of the form that was previously posted.
Therefore, when the value of combo box 'number of combo boxes'
is posted to the second html view you can easily access the value
selected by calling
$HTTP_POST_VARS['name of your select field']
In your form you will need to intialize the method as 'method=post' for this to work
i.e.
Create 2 seperate html forms to get the data you need to build the final new html form
CODE:
<body>
<?php
//check to see if there are any posted elements
//by utilizing if...elseif statements
//if not it will default to first form
if(!$HTTP_POST_VARS)
{
?>
Form 1:
<form name=form_1 action=index.php method=post>
<select name=number>
<option value=1 selected=selected>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
<p>
<input type=submit name=submit value=" Next Step ">
<input type=hidden name=form value="step2"> <!-- pass a hidden field for which form -->
</p>
</form>
<?php
}
elseif($HTTP_POST_VARS[form] == "step2")
{
?>
Form 2:
<form name=form_2 action=index.php method=post>
<table border=0 cellpadding=0 cellspacing=2>
<tr>
<td colspan=2>
Please Select Database Fields For Combo Boxes:
<hr size=2 width=100% noshade=true>
<td>
</tr>
<tr>
<td>
<font color=green><b>Combo Box Number</b></font>
</td>
<td>
<font color=green><b>Database Field</b></font>
</td>
</tr>
<tr>
<td colspan=2 valign=top>
<hr size=1 width=100% noshade=true><br><br>
</td>
</tr>
<?php
//A little php code to iterate each combo box number
//and to display a combo box for all the different
//field choices
//get the number of combo boxes to be displayed
$number = $HTTP_POST_VARS[number];
//initialize an array to hold names for the combo boxes
$combo = array();
//need a naming format for each combo box
//to be able to access combo box names when
//$HTTP_POST_VARS is called, this format will be used
// combo-2
for($i=0;$i < $number;$i++)
{
$num = $i + 1;
$combo[$i] = "combo-" . $num;
}
//iterate through each combo box and display name
//and provide a drop down combo box to retrieve what
//database field is to be assigned to it
for($i=0;$i < $number;$i++)
{
$num = $i + 1;
echo("<tr><td>Combo Box " . $num .
"</td><td><select name=" . $combo[$i] . ">" .
"<option value=first_name>First Name</option>" .
"<option value=last_name>Last Name</option>" .
"<option value=person_id>ID Number</option>" .
"</select>" .
"</td></tr>");
}
?>
<tr><td colspan=2><br><br></td></tr>
<tr>
<td colspan=2 valign=top>
<hr size=1 width=100% noshade=true><br><br>
</td>
</tr>
<tr>
<td colspan=2 valign=bottom>
<input type=submit name=submit value=" View New Form ">
<input type=hidden name=number value='<? echo($HTTP_POST_VARS[number]) ?>'>
<input type=hidden name=form value="step3">
</td>
</tr>
</table>
</form>
<?php
}
elseif($HTTP_POST_VARS[form] == "step3")
{
?>
The New Form:
<form action=index.php method=post>
<table border=0 cellpadding=0 cellspacing=2 width=50%>
<tr>
<td>
Please Select Data To Be Displayed:
<hr size=2 width=100% noshade=true><br><br>
<td>
</tr>
<?php
//Initialize a variable called $cnt to be used to store
//the number of data objects that are stored in all fields
$cnt_num = 0;
$cnt_data = array();
$cnt = "";
foreach($HTTP_POST_VARS as $key => $value)
{
//Execute for all $HTTP_POST_VARS except not submit button and hidden fields
if($key != "submit" and $key != "form" and $key != "number")
{
//select the data in the field and assign it to array $result
$select = "select " . $value . " from person";
$result = mysql_query($select);
//iterate each combo box and all the field data in them as options
echo("<tr><td><select name=" . $key . " multiple=false>");
while($row = mysql_fetch_array($result))
{
$row_size = sizeof($row);
for($i=0;$i < $row_size;$i++)
{
//increment $cnt by 1
$cnt_num = $cnt_num + 1;
$data = trim($row[$i]);
if($data)
{
echo("<option value=" . $data . ">" . $data . "</option>");
}
}
}
echo("</select></td></tr><tr><td><br></td></tr>");
$cnt_data = array_push($cnt);
$cnt_num = 0;
}
}
//Get the largest value in $cnt_data array
//this will be used to determine the colspan value
//we will need for the next view
$cnt_data = array_unique($cnt_data);
$cnt_data = sort($cnt_data);
$num_cnt_data = sizeof($cnt_data) - 1;
$cnt = $cnt_data[$num_cnt_data];
?>
<tr><td><br><br></td></tr>
<tr>
<td colspan=2 valign=top>
<hr size=1 width=100% noshade=true><br><br>
</td>
</tr>
<tr>
<td colspan=2 valign=bottom>
<input type=submit name=submit value=" View Data ">
<input type=hidden name=form value="view_data">
<input type=hidden name=number value='<? echo($HTTP_POST_VARS[number]) ?>'>
<input type=hidden name=cnt value='<? $cnt ?>'>
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>