multiple execution of a mysql query with php
Posted: Tue Sep 14, 2004 3:04 am
I have the next code
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?
I would appreciate some help.
Code: Select all
$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";
}
}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?
I would appreciate some help.