How do i Select to other table

Hi, I am trying to select data to other table but unfortunately i always got error on this.


       $cn=$db->prepare("select empid,empjob
                          from employee");
        $cn->execute();

        while($row =  $cn->fetch(PDO::FETCH_ASSOC)){
                 $empid = $row['empid'];

                     $cn=$db->prepare("select actempid, actaddress
                          from empact
                         where actempid = $empid");
                        $cn->execute();

                some codes ............
              ................................

        }

is this okay to use ?please correct me if i am wrong.

Thank you in advance.

Hi jemz,

The problem is that you’re re-assigning the variable $cn for your queries inside the while loop, but it’s still in use to loop through your first query. If you use a different variable inside the loop you should be OK.

Hi fretburner, Thank you for the reply…I it’s working,…Thank you so much :slight_smile: :slight_smile: :slight_smile:

Many regards.

Hi fretburner,Thank you again for helping me to solve my problem…:slight_smile:

No worries, you’re welcome :slight_smile: