如何使用mysql中的数据在PHP中创建矩阵


how to create matrix in PHP with data from mysql?

我在mysql中有这个表,表"distance":

id |距离|1|8|2|5|3|7|

我想要输出,例如:

8 5 78 5 78 5 7

如何在php中进行编码?谢谢,我是PHP的新手。

像这样尝试

$tableRows[0]=array("id"=>1,"distance"=>8);
$tableRows[1]=array("id"=>2,"distance"=>5);
$tableRows[2]=array("id"=>3,"distance"=>7);
$counter=0;
foreach($tableRows as $tableRow)
{
    foreach($tableRows as $tableRow)
    {
        echo $tableRow["distance"]."'t";
    }
    echo "'n";
}

在线演示