title: looping php mysql query till no result found
body: <p>I have this mysql query that i want to loop till there is no more result found in the table,</p>
  
  <pre><code>$sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  
  }
  </code></pre>
  
  <p>and what i want is loop the same query again and again like this:</p>
  
  <pre><code>$sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  
  $sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  
  }
  }
  </code></pre>
  
  <p>this last code will loop the query twice but the problem i have is that i want to loop it till there is no more result found </p>
  
  <pre><code>$sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  </code></pre>
  
  <p>&lt;--! REPEAT SAME CODE IN HERE AGAIN AND AGAIN AND AGAIN -->
      }</p>
  
  <p>looping 3 times:</p>
  
  <pre><code>$sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  
  $sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  
  $sql_query="select id from rev_r_clients WHERE parent_client_id='$id'";
   $res = mysql_query($sql_query);
   $ids=array();
   while($row = mysql_fetch_object($res)){
   $ids[]=$row-&gt;id;
  }
   $ids=array_filter($ids);
   foreach($ids as $id){
   echo $id;
  
  }
  }
  }
  </code></pre>
  
  <p>so how do i repeat the code infinite times till there is no result in the database</p>