title: How to find out if parent have children in php mysql
body: <p>It have two table parent table and children table</p>
  <p><strong>Parent Table</strong></p>
  <pre><code>id   page-title    page-content
  </code></pre>
  <p><strong>Children Table (where parent_id = id) id from parent table</strong></p>
  <pre><code>child_id   parent_id   child-title   child-content
  </code></pre>
  <p><strong>Now How to find out if parent have any children</strong></p>
  <pre><code>&lt;?php
  //parent table
  $data = $conn-&gt;query(&quot;SELECT * FROM parent_page ORDER BY id DESC&quot;);
  while($rows = $data-&gt;fetch(PDO::FETCH_OBJ) ):
      $parent_id = $rows-&gt;id;
  ?&gt;
  
  &lt;?php 
      //chlidren table
      $child_data= $conn-&gt;query(&quot;SELECT * FROM children_page WHERE parent_id = $parent_id &quot;);
      while($child_rows = $child_data-&gt;fetch(PDO::FETCH_OBJ) ):
           $child_rows-&gt;parent_id;
   ?&gt;
  &lt;?php
  //requirement check if parent have children (how to check if parent have children or not)
  if('parent have children'){
      then echo children content;
  }else{
      echo parent content;
  }
  ?&gt;
  
  &lt;?php endwhile; endwhile;?&gt;
  </code></pre>