php在循环中爆炸数组并加入

时间:2013-03-04 06:12:44

标签: php

我使用group concat将id作为uid连接起来 uid列分组为68,94,97,88,93,69,95  我想引用其他表并获取每个id的名称,因为我爆炸了下面给出的数组

如何获取$arrurtype数组中的$row

    $rs = mysqli_query($dbc,"SELECT A.* ,    
   GROUP_CONCAT( `B`.`uid` ) AS `uid`
       FROM A
        JOIN B
          ON A.id = B.id
       GROUP BYA.Section_Id  limit $offset,$rows");
  $items = array();   
          $i=0;
while($row = mysqli_fetch_object($rs))
       { 
        $idSysUsers = $row->idSysUsers;    
     $exp =  explode(',',$idSysUsers);  
      foreach($exp as $val)
          {
        $qUTdd = "SELECT  uname from users where  `uid = '".$val."'";     
    $q11 =  mysqli_query($dbc,$qUTdd);      
     $rrr = mysqli_fetch_object($q11);
        $arrurtype[] = $rrr->uname;
       }     


$row = array(   
 'cola1' =>$row->a1,
'cola2'=>$row->a2,
    'cola3'=>$row->a3,
    'cola4'=>$row->a4,
'cola5'=>$arrurtype
  );   
    array_push($items, $row);
  //$i++;
}

1 个答案:

答案 0 :(得分:0)

如果您以逗号分隔格式获取ID,则需要使用IN来获取这些ID中的所有用户。而不是像你拥有的那样多循环!!

现在$rrr将包含您要求的所有用户。

    $idSysUsers = $row->idSysUsers;
    $usersnames = "SELECT  uname from users where  `uid IN ('".$idSysUsers."')";      
    $q11 = mysqli_query($dbc,$qUTdd);
    $rrr = mysqli_fetch_object($q11);