从数据库中填充数组

时间:2012-03-15 17:01:33

标签: mysql

//我需要一个来自我的数据库的输出数组, //我试过了:

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php

$query = "SELECT * FROM pages";

$result = mysql_query($query);
$aUsers = array();
while($row = mysql_fetch_array($result))
{

   $row["menu_name"];

}

//我需要得到类似的东西:

$aUsers = array(
        "Ädams Egbert",
        "Altman Alisha",
        "Archibald Janna",
        "Auman Cody",
        "Bagley, Sheree");

//我需要一个填充了数据库“pages”中的行“menu_name”的数组

//我怎么能这样做,有人可以帮助我吗?!

1 个答案:

答案 0 :(得分:3)

如果您只需要menu_name,则只应在查询中选择menu_name

$query = "SELECT menu_name FROM pages";

$result = mysql_query($query);
$aUsers = array();
while($row = mysql_fetch_array($result)){

   $aUsers[]=$row["menu_name"];

}

print_r($aUsers); //display on page for testing