我是否在数据库中的字段名(Name)中获取所有数据并将其存储在变量数组中?在PHP和MYSQL中

时间:2011-05-24 07:02:09

标签: php mysql database arrays loops

$name = mysql_num_rows($result);
$i = 0;
while($i < $name){  
    $nameAll = mysql_result($result, $i);           
    $i++;   
}

1 个答案:

答案 0 :(得分:1)

您可以使用第一个示例中的代码here

$sql = "SELECT id as userid, fullname, userstatus 
        FROM   sometable
        WHERE  userstatus = 1";

    $result = mysql_query($sql);

    // While a row of data exists, put that row in $row as an associative array
    // Note: If you're expecting just one row, no need to use a loop
    // Note: If you put extract($row); inside the following loop, you'll
    //       then create $userid, $fullname, and $userstatus
    $values = array(); 
    while ($row = mysql_fetch_assoc($result)) {

        $values[] = $row["fullname"];

    }