我正在尝试将类似“SELECT * FROM sales”的MySQL结果转换为如下所示的数组:
$data = array(
array('Date', 'Sales'),
array('June 25', 12.25),
array('June 26', 8.00)
);
我用while
循环尝试了它,但它没有用。我怎么能这样做?
答案 0 :(得分:0)
试试这个:
$query = "SELECT * FROM sales";
$data = array();
$data[] =array('Date', 'Sales');
if ($result = $mysqli->query($query))
{
while ($line = $result->fetch_assoc())
{
// line contain an associative array with "Date" and "Sales"
$data[] = array($line['Date'], $line['Sales']);
}
}
$result->free();