在没有while语句php的情况下返回单个查询中的所有数据

how to get all data in single array without using while statement. here is some code but its not working good.. any idea about whole query result in sigle assoc array.. any idea??

$data=array();
$sql = "SELECT `Name`, `Title`, `Version`, `Date`, `Cover`, `Content` FROM dict";
$result=mysql_query($sql);

while($data[]=mysql_fetch_assoc($result))
{
$data[]=mysql_fetch_assoc($result);
}
print_r($data);

You can wrap it into a function of it's own (and correct the error) so you can't mis-type it any longer:

mysql_fetch_assoc_all($result)
{
    $data = array();
    while  ($row = mysql_fetch_assoc($result))
    {
        $data[] = $row;
    }
    return $data;
}

Usage:

$sql = "SELECT `Name`, `Title`, `Version`, `Date`, `Cover`, `Content` FROM dict";
$result = mysql_query($sql);
$data = mysql_fetch_assoc_all($result);

Take care that $result must be a valid result.

The reason why it's not working is how you do your loop.

while($row = mysql_fetch_assoc($result))
{
    $data[] = $row;
}

Then you have an array of associative arrays in $data.

I'm not aware of any "single-line" solution. Although you can of course wrap all this in a function as hakre suggests.

Little bit late, but "single line" could be:

while($data[] = mysql_fetch_assoc($result));