How to Fetch data from while loop inside a while loop
<p>I have this code and thing it's a weird but when I get the last_name from the first query which is a unique number and with the help of that I get the Spell of the last name from another table but when I try to get another data just below the second which ends it thinks that the first while loop has ended and then I can't get the rest of the data from the first while loop and I even tried this code but unfortunately it didn't worked for me</p>

<pre><code>&lt;div class="row"&gt;
    &lt;?php 
    $sql2 = "SELECT id,last_name,age,height,weight,gender,education,work
             from profile where parent_key!='$parent_key' ";
    $retval2 = mysqli_query($con,$sql2);

    if(! $retval2 ) {
        die('Could not get data: ' . mysql_error());
    }

    while($row = mysqli_fetch_array($retval2, MYSQL_ASSOC)) {
    ?&gt;

    &lt;div class="row"&gt;
        &lt;div class="col-lg-6 col-md-6 col-sm-6"&gt;
            &lt;span&gt;Unique Id&lt;/span&gt;
            &lt;h3&gt;&lt;?php  echo $row['id'] ?&gt;&lt;/h3&gt;
        &lt;/div&gt;
    &lt;div class="col-lg-6 col-md-6 col-sm-6"&gt;
        &lt;span&gt;Surname&lt;/span&gt;
        &lt;h3&gt;&lt;?php $surname = $row['last_name']; 
            $sql3 = "SELECT last_name from surname where id='$surname'";
            $retval3 = mysqli_query($con,$sql3);
            if(! $retval3 ) {
                die('Could not get data: ' . mysql_error());
            }
            while($row = mysqli_fetch_array($retval3, MYSQL_ASSOC)) {
                echo $new_last_name ="{$row['last_name']}";
            ?&gt;
            ?&gt;
        &lt;/h3&gt;
    &lt;/div&gt;

&lt;/div&gt;
&lt;!-- /.row --&gt;


&lt;!-- /.row --&gt;

&lt;?php
    }
?&gt;

&lt;?php
    }
?&gt;
&lt;/div&gt;
&lt;!-- /.row --&gt;
</code></pre>

<p>And Thanks for helping in advance.</p>