title: How to pass php variable outside of while loop within same page
body: <p>I have faced small problem regarding passing php variable outside of PHP loop. I have created table and form in same page. First table is displayed and the through edit link in form pop up dialog box appears. I want to pass dynamic ID to dialog box after click edit link. My page includes a php table and form.</p>
  
  <p><strong>PHP/HTML Table</strong></p>
  
  <pre><code>&lt;table&gt;
      &lt;th&gt;ID&lt;/th&gt;
      &lt;th&gt;Title&lt;/th&gt;
      &lt;th&gt;Edit&lt;/th&gt;
          &lt;?php
              $query="select * from video order by id desc";
              $result=$con-&gt;query("SELECT * FROM video ORDER by id DESC") or die($con-&gt;error);
              while($row=$result-&gt;fetch_assoc()){
                  $id=$row['id'];
                  $heading=$row['heading'];
          ?&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;?php echo $id ?&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;?php echo $heading ?&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;a href="#modal2" id="pop_button"&gt;Edit&lt;/a&gt;
          &lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php } ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>After this table, I want to display data in this form</p>
  
  <p><strong>PHP Form in dialog box</strong></p>
  
  <pre><code>&lt;div class="remodal" data-remodal-id="modal2" role="dialog" aria-labelledby="modal2Title" aria-describedby="modal2Desc"&gt;
      &lt;form action="" method="POST" enctype="multipart/form-data"&gt;
          &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;Video ID&lt;/th&gt;
              &lt;td&gt;
                  &lt;input type="number" value="&lt;?php echo $id?&gt;" name="id" readonly&gt;&lt;/input&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Video Title&lt;/th&gt;
              &lt;td&gt;
                  &lt;input type="text" value="&lt;?php echo $heading?&gt;" name="title"&gt;&lt;/input&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;/table&gt;    
      &lt;/form&gt; 
  &lt;/div&gt;
  </code></pre>
  
  <p>I know that while loop can't connect to popup dialog box form, so my code prints only data of first row. If I include whole code within while loop, my table structure become mess. Is there any idea to <strong>pass ID outside of while loop</strong> ? I tried using global variable method, but it doesn't work. Perhaps I can't properly use <strong>global variable</strong>. Thanks</p>