更新时间:2023-01-16 21:47:01
$ IDS =阵列();
而($行= mysql_fetch_object($水库)){
IDS [] = $行级别和SEQ ID;
}
$ IDS = array_filter($ IDS);
/ *要删除空数组* /
的foreach($ ID作为的$ id){
回声$ ID;
}
Any one have idea how to do the following:
I have the following mysql query :
client 1026 has two clients under him: 1056 (on the left ) & 1497 ( on the right ) and each of client 1056 and client 1497 has two other clients under them, and so on
now i want to make a loop to collect all the clients under the client 1026
i have this mysql query
$sql_query="select id from rev_r_clients WHERE parent_client_id='1026'";
$res = mysql_query($sql_query);
$ids=array();
while($row = mysql_fetch_object($res)){
$ids[]=$row->id;
}
$ids=array_filter($ids);
foreach($ids as $id){
echo $id;
echo '<br>';
$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->id;
}
$ids=array_filter($ids);
foreach($ids as $id){
echo $id;
}
}
it return
1056
106410801497
15051521
now how can i make this query get array result ( like 1056,1497 ) and then use foreach loop to get the result and the result of the result of the result etc.. until there is no more result?
You can use mysql , mysqli , PDO all i want is to accomplish the request
$ids=array();
while($row = mysql_fetch_object($res)){
ids[]=$row->id;
}
$ids=array_filter($ids);
/*To remove empty array*/
foreach($ids as $id){
echo $id;
}