SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post 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.

    PHP Code:
           $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.

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,402
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    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.

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    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

    Many regards.

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi fretburner,Thank you again for helping me to solve my problem...

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,402
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by jemz View Post
    Hi fretburner,Thank you again for helping me to solve my problem...
    No worries, you're welcome


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •