title: Retrieve id from stored procedure to call nested procedure - PHP and MYSQL
body: <p>I need to call a first procedure (CrushProps) and then loop through each row by calling a second procedure (CrushOutcomes) with a value (PropId) from the row in the results from the first (and return all rows from the new procedure).</p>
  
  <p>I have looked at this question but cannot make it work for me:
  <a href="https://stackoverflow.com/questions/18960672/calling-nested-stored-procedure-from-php?newreg=caff0e862d7f45ee87d3a7365a363fe4">calling nested stored procedure from php</a></p>
  
  <p>These are the two stored procedures:</p>
  
  <pre><code>DROP PROCEDURE IF EXISTS CrushProps $$
  create procedure CrushProps(IN crID int)
  begin
  
  select props.PropText, props.Prop_Id 
  from props inner join crush_props on props.Prop_Id = crush_props.PropId
  where crush_props.CrushId = crID;
  end $$
  
  DROP PROCEDURE IF EXISTS CrushOutcomes $$
  create procedure CrushOutcomes(IN prID int)
  begin
  
  select prop_outcomes.OutcomeText, prop_outcomes.OutcomePoints  
  from prop_outcomes inner join crush_props ON prop_outcomes.PropId = crush_props.PropId
  WHERE prop_outcomes.PropId = prID;
  
  end $$
  </code></pre>
  
  <p>Being new to PHP and MySQL I have tried many different variations without any luck. The code below runs thru the two procedures sequentially and returns all rows from the first but only one row from the second (and AFTER the full result - not after each row).</p>
  
  <p>I cannot figure out how to make it loop thru each row of the first procedure.</p>
  
  <pre><code>$result = mysqli_query($con,"CALL CrushProps('$crushid')") or die("Query fail: " . mysqli_error());
  
  if($result-&gt;num_rows &gt; 0) 
  {
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
      {
     $prptxt = $row[PropText];
     $prpid = $row[Prop_Id];
  
      echo $prptxt . "&lt;br/&gt;"; 
      }
  
              $result-&gt;close();
              $con-&gt;next_result();
  }
  
  
  $result2 = mysqli_query($con,"CALL CrushOutcomes('$prpid')") or die("Query fail: " . mysqli_error());
  
  if($result2-&gt;num_rows &gt; 0) 
  {
      while($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC))
      {
     $outtxt = $row2[OutcomeText];
     $outpts = $row[OutcomePoints];
  
      echo $outtxt . "&lt;br/&gt;"; 
  
      }
  }    
  </code></pre>