Hi all,

3 tables :
one events table (each event can have differents types)
one types table (each type can have differents events)
one liaison table (link between events and types tables)

I have some problems when I show screen.

<select name="type[]" size="10" multiple="multiple">
$req_type   = "SELECT * FROM type ORDER BY type ASC";
$res_type   = mysql_query($req_type);
$req_liaison   = "SELECT * FROM liaison WHERE id_ev = $id";
$res_liaison   = mysql_query($req_liaison);
$ligne_liaison = mysql_fetch_array($res_liaison);
while ($ligne_type = mysql_fetch_array($res_type))
<option value="<?php echo $ligne_type['id'] ?>" <?php if (isset($ligne_liaison) && in_array($ligne_type['id'], $ligne_liaison)) { echo 'selected="selected"'; } ?>><?php echo $ligne_type['type'] ?></option>

The selected don't run and don't show correct value.

Can you help me ?

Thanks a lots

please show structure of tables and add in 17 line

print_r( $ligne_liaison );

if values not empty, or write more about truoble

Just replace $columnName with the actual column name you want in the select tag. The actual query doesnt have to be in the select tag. The loop is what has to be inside the select tag. Hope this helps.
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
//This is the datbase connection
$con = mysql_connect("localhost","UserName","Password") or die("Check connection");


$query = "SELECT * FROM TableName ORDER BY columnName";



extract($row); // This is what you were missing

echo "<option value='$columnName'>".$columnName."</option>";

$row++; // this is what you were missing
//This will output every column name



I must recover selected option


Yes, when I put this code (print_r)
I have one record only and in my test there are 3 records.
my request is not really wrong but incomplete for my problem

$ligne_liaison = mysql_fetch_array($res_liaison);


I resolve my problem. :)
I made a array with my last request in a while instruction.

After I put :

<?php if (in_array($line_type['id'], my_array)) { echo 'selected="seleted"'; } ?>

Thanks for ur help (print_r, ...)