php获取用户下拉列表

how do i get dropdown selected for each user.

user table
------------
id    job
1     1
2     2

job table
----------
id   name
1    Doctor
2    Sales

$q = $db->query("SELECT * FROM affiliate LEFT JOIN user ON user.job = affiliate.id_affiliate");
        while($r = $q->fetch_array()) :
            if($r['id_user'] == $_SESSION['id_user'] && $r['job'] == $r['id_affiliate']) {
                echo '<option selected value="'.$r['id_affiliate'].'">'.$r['org'].'</option>'; 
            } else {
                echo '<option value="'.$r['id_affiliate'].'">'.$r['org'].'</option>'; 
            }
        endwhile;

selected="selected" or just selected should normally work. If not there is a problem with your if statement. One simple way is to echo out the content of the if statement like this:

note!! the echo should normally be done outside the select open tag, just paste the following outside the select open tag but just after your query.

 while($r = $q->fetch_array()) :
        echo $r['id_user'] .'=='. $_SESSION['id_user'] .'&&'. $r['job'] .'== '.$r['id_affiliate'].'<br />';
 endwhile;

you can now check if the values actually match. if not then there is your problem.

How about modifying the following ...

if( ($r['id_user'] == $_SESSION['id_user']) && ($r['job'] == $r['id_affiliate']) )

Not sure if it matters, but I have selected at the end of my option.

<option value='cat' selected>