title: Nested While loop not working correctly php
body: <p>I am trying to get some data from my sql. But the result for the $arra_detail[] keeps repeating ... here is my code .. please review it and let me know of the mistake I am making .. any help will be appreciated ..  </p>
  
  <pre><code>//Process of getting data from table
  $sql = "SELECT * FROM projects JOIN project_details ON projects.project_id=project_details.project_id";
  
  $results = $conn-&gt;query($sql);
  
              if($results-&gt;num_rows &gt; 0){
                 while($row = $results-&gt;fetch_assoc()){
  
                     $pid = $row["project_id"];
                     $detailQuery = "SELECT * FROM project_details WHERE project_id = $pid";
                     $details = $conn-&gt;query($detailQuery);
                     if($details-&gt;num_rows &gt; 0){
                         while ($r = $details-&gt;fetch_assoc()){
                             $projectDetails[] = array(
                                 "project_detail" =&gt; $r["project_detail"],
                                 "project_payment" =&gt; $r["project_payment"],
                                 "project_payment_date" =&gt; $r["project_payment_date"],
                                 "project_payment_status" =&gt; $r["project_payment_status"]
                             ); 
                         }
                     }
  
                     $data[$row["project_name"]] = array(
                         "project_id" =&gt; $row["project_id"],
                         "project_start_date" =&gt; $row["project_start_date"],
                         "project_due_date" =&gt; $row["project_due_date"],
                         "project_currency" =&gt; $row["project_currency"],
                         "poject_details" =&gt; $projectDetails
                     );
  
  
                 }
                 echo "&lt;pre&gt;",  print_r($data) , "&lt;/pre&gt;";
              } else{
                  echo "No data found ";
              }
  </code></pre>