-1

我使用组 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++;
}
4

1 回答 1

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); 
于 2013-03-04T06:21:25.223 回答