问题描述
任何一个有想法如何做到以下几点:
我有以下MySQL查询:
客户端1026下面有两个客户端:1056(左)及1497(右侧)
和每个客户端1056和客户1497具有根据他们其他两个客户端,等等
现在我想打一个循环来收集所有的客户的下1026
我有这样的MySQL查询
$ sql_query =选择rev_r_clients WHERE parent_client_id ='1026'身份证;
$解析度=的mysql_query($ sql_query);
$ IDS =阵列();
而($行= mysql_fetch_object($水库)){
$编号[] = $行级别和SEQ ID;
}
$ IDS = array_filter($ IDS);
的foreach($ ID作为的$ id){
回声$ ID;
呼应'< BR>;
$ sql_query =选择rev_r_clients WHERE parent_client_id ='$ ID身份证;
$解析度=的mysql_query($ sql_query);
$ IDS =阵列();
而($行= mysql_fetch_object($水库)){
$编号[] = $行级别和SEQ ID;
}
$ IDS = array_filter($ IDS);
的foreach($ ID作为的$ id){
回声$ ID;
}
}
其返回
1056
106410801497
15051521
现在我怎样才能让这个查询得到数组结果(如1056,1497),然后使用foreach循环得到的结果,结果等,直到有没有更多的结果,结果的结果?
您可以使用MySQL,库MySQLi,PDO我要的就是完成请求
$ 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;
}
这篇关于PHP的MySQL查询结果数组,foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!