php mysql编码问题

I am trying to match the id from table 1 if it is present in table 2 if the id is present in table 2 redirect some where once this is done, i am trying to match id of table 1 is present in table 2 with if table 2 has primary id redirect some where else redirect some where

The below is the code Can any person help me with it?

<?php
include "../config/config.php";
$uid=$_GET['id'];

                            $sql2="SELECT id,uid FROM don_fee_student";
                            $result2=mysql_query($sql2);
                            $count2=mysql_num_rows($result2);

                            if($count2>0){

                                while ($row2=mysql_fetch_array($result2)) {

                                    $id = $row2['uid'];
                                    $aid=$row2['id'];

                                }
                                }else{
                                    echo "No Records found";
                                }

if ($uid==$id) {
    header("location:../college_fees_request.php?id=".$uid);
}
if (($uid==$id)&&(!empty($aid))) {

       header("location:../col_fees_al_req.php?id=".$uid);   
}
if (($uid==$id)&&(empty($aid))) {
 header("location:../add_don_app.php?id=".$uid);   
}
?>

When I am going to write on this much instead of the above if statement, it works.. but i also need to check if the table 2 has user id and application id it needs to redict to some where

if ($uid==$id) {
    header("location:../college_fees_request.php?id=".$uid);

}
else 
{
 header("location:../add_don_app.php?id=".$uid);   
}