$query_1 = "SELECT id, name FROM languages ORDER BY name ASC";
$result_1 = mysql_query($query_1) or die ("Error in query: $query. " .mysql_error());
for ($i = 1; $i <= 6; $i++)
{
print "<tr>
<td><select name="laguage_$i">";
while ($row_1 = mysql_fetch_object($result_1))
{
print "<option value="$row_1->id">$row_1->name</option>\n";
}
}
What I want is to print 6 times the same language selection list including values from a database.
Right now the code is executed 6 times and I get 6 selection lists, but only in the first one I get the values from the database. I think that this can be probably because the $row_1 variable name is always the same, and it can´t be. Or what?... Is there any way of changing its name for each execution?
$query_1 = "SELECT id, name FROM languages ORDER BY name ASC";
$result_1 = mysql_query($query_1) or die ("Error in query: $query. " .mysql_error());
$selectoptions = "";
while ($row_1 = mysql_fetch_object($result_1))
{
$selectoptions .= "<option value="$row_1->id">$row_1->name</option>\n";
}
for ($i = 1; $i <= 6; $i++)
{
print "<tr>
<td><select name="laguage_$i">$selectoptions</select>";
}
Ok, now another question about the same. What I should do if I want to print the same list, but with a selected option? A selected option will be printed if the user has already inserted a value to the database through this list, otherwise it will be printed without a selection.
So then, when the user goes to edit his data, he sees what he has previously inserted and he can change it.