title: how to update a field in mysql pdo from another table
body: <p>This is not a duplicate question. The previous question is nothing to do with PDO. I have two tables in mysql:</p>
  
  <pre><code>USERS
  -------------------------------------
  employeeid  | name | saving | salary
  -------------------------------------
  12           | Bob | 100     | 1000
  23           | Joe | 50      | 800
  
  USERS table
  employeeid
  name
  saving
  salary
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>EMPLOYEE
  -----------------------------------
  id   |  managerid  | workerid
  -----------------------------------
  1    |    12       |  23
  
  EMPLOYEE table
  id
  managerid FOREIGN KEY
  workerid FOREIGN KEY
  </code></pre>
  
  <p>1- (both manager and worker are employee) in order to update the saving field for a workerid (say with +$10), field salary needs to be updated by -$10</p>
  
  <p>2- input variable comes from PHP form as <code>name</code> , so the logical flow is:</p>
  
  <pre><code>name  &gt; find employeeid (id) from USERS &gt; find managerid (id2) from EMPLOYEE &gt; find employeeid (id3) from USERS &gt; update saving and salary
  </code></pre>
  
  <p>so the sql statement separately can be written as:</p>
  
  <pre><code>id = SELECT employeeid FROM USERS WHERE name = $name;   //find id of employee in USERS
  id2 = SELECT managerid FROM EMPLOYEE WHERE workerid = id; //find id of worker in EMPLOYEE
  UPDATE USERS SET saving = saving + 10, salary = salary -10 WHERE employeeid = id2;
  </code></pre>
  
  <p>is it possible to do these 3 statements in one (in PDO format).
  msql PDO format of above (with PHP):</p>
  
  <pre><code>$sql = "SELECT employeeid FROM USERS WHERE name=:namepara";
  $sttm = prepare($sql);
  $sttm-&gt;execute(array(":namepara"=&gt;$name));
  $row=$sttm-&gt;fetch(PDO::FETCH_ASSOC);
  
  $sql2 = "SELECT managerid FROM EMPOYEE WHERE workerid=:idpara";
  $sttm2 = prepare($sql2);
  $sttm2-&gt;execute(array(":idpara"=&gt;$row['employeeid']));
  $row2=$sttm2-&gt;fetch(PDO::FETCH_ASSOC);
  
  $sql3 = "UPDATE USERS SET saving = saving + 10, salary = salary - 10 WHERE 
     employeeid=:id2para";
  $sttm3 = prepare($sql3);
  $sttm3-&gt;execute(array(":id2para"=&gt;$row2['managerid']));
  $row3=$sttm3-&gt;fetch(PDO::FETCH_ASSOC);
  </code></pre>
  
  <p>Any help would be appreciated!</p>