将查询转换为数组,然后一次使用 2 个


Turn a query into a array and then use 2 at a time

$q = "SELECT u.username, p.position FROM ".TBL_FOOT_TOUR_PLAYERS." p
    INNER JOIN ".TBL_USERS." u ON p.userid = u.id
    WHERE p.tourid = '$tour_id' ORDER BY position";
    $result = $database->query($q);
    while($row=mysql_fetch_assoc($result)){
}

我想同时获取用户名和位置并将它们放在一个数组中。

然后,我希望能够每 2 个条目访问该数组。

我该怎么做呢?

谢谢

听起来你只是想做这样的事情:

$info = array();
while ($row = mysql...) {
   $info[] = $row['username'];
   $info[] = $row['position'];
}

这将为每两个条目提供用户名/位置。 然而,这有点奇怪。 相反,你可能只想做

$info[] = $row;

这将为您提供一个数组,如下所示:

 0 => array('username' => 'whatever', 'position' => 'whatever')
 1 => array('username' => 'whatever1', 'position' => 'whatever1')