It have two table parent table and children table
Parent Table
id page-title page-content
Children Table (where parent_id = id) id from parent table
child_id parent_id child-title child-content
Now How to find out if parent have any children
<?php
//parent table
$data = $conn->query("SELECT * FROM parent_page ORDER BY id DESC");
while($rows = $data->fetch(PDO::FETCH_OBJ) ):
$parent_id = $rows->id;
?>
<?php
//chlidren table
$child_data= $conn->query("SELECT * FROM children_page WHERE parent_id = $parent_id ");
while($child_rows = $child_data->fetch(PDO::FETCH_OBJ) ):
$child_rows->parent_id;
?>
<?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;
}
?>
<?php endwhile; endwhile;?>