-3

很确定这很容易,但我无法弄清楚,基本上是这样的简单查询:

$result = $mysqli->query("SELECT t.name FROM cups_participants cp
              LEFT JOIN teams t on cp.team_id  = t.team_id
              WHERE cp.cup_id = '1'");

上面的查询应该从数据库中获取所有名称,现在我希望它像这样放入数组中:

$competitors = array(
 'Paul A.M. Dirac', 
 'Hans Christian Oersted', 
 'Murray Gell-Mann', 
 'Marie Curie', 
 'Neils Bohr', 
 'Richard P. Feynman', 
 'Max Planck');

我如何将查询的结果放入上面的数组中?

4

1 回答 1

0
$competitors = array();

$result = $mysqli->query("SELECT t.name FROM cups_participants cp
          LEFT JOIN teams t on cp.team_id  = t.team_id
          WHERE cp.cup_id = '1'");

if($result->num_rows > 0)
{
    while($rs = $result->fetch_assoc())
{
       $competitors[]=$rs['name'];
    }
}

echo "<pre />";
print_r($competitors);
于 2013-05-06T09:46:04.297 回答