problem comparing two queries
Posted: Fri Sep 17, 2004 12:45 am
Hi guys,
I´m trying to find some help to this problem
I have two queries the first one ($query_u) gets all the languages stored in a batabase table called language.
The second ($query_u2) gets all the selected languages that are stored to a table called language_level.
So I want to print a form by which the user can edit his previously inserted language values. There are 6 lists of languages and all have different names (language_1, language_2...language_6). So what I want is that if the user has selected 3 languages of the 6, I want to pront the first 3 lists with the selected languages listed as a "SELECTED" option.
Here is the code I use:
With this code I only getting one of the 3 selected languages, which is actually the first in the language_level table. I see that the $selection variable is only containing one of the values, and it has to contain 3 actually.
What is wrong in the code? How can I fix it?
I´m trying to find some help to this problem
I have two queries the first one ($query_u) gets all the languages stored in a batabase table called language.
The second ($query_u2) gets all the selected languages that are stored to a table called language_level.
So I want to print a form by which the user can edit his previously inserted language values. There are 6 lists of languages and all have different names (language_1, language_2...language_6). So what I want is that if the user has selected 3 languages of the 6, I want to pront the first 3 lists with the selected languages listed as a "SELECTED" option.
Here is the code I use:
Code: Select all
for($i = 1; $i <= 6; $i++)
{
$query_u = "SELECT id, name FROM language ORDER BY name ASC";
$result_u = mysql_query($query_u) or die ("Error in query: $query_u. " .mysql_error());
$query_u2 = "SELECT language_id FROM language_level WHERE user_id ='$row_b->id'";
$result_u2 = mysql_query($query_u2) or die ("Error in query: $query_u2. " .mysql_error());
$selectoptions = "";
while ($row_u = mysql_fetch_object($result_u))
{
$selectoptions .= "<option value="$row_u->id" ";
while($selection = mysql_fetch_object($result_u2))
{
if($selection == "$row_u->id")
{
$selectoptions .= "selected";
}
}
$selectoptions .=">$row_u->name</option>\n";
}
}What is wrong in the code? How can I fix it?