我有一张桌子,例如 col A col B col C col D
while ($result = mysql_fetch_assoc($query)) {
// code here to echo all data you need
// for example echo $result['colA'], $result['colB']
}
我需要的是以下内容:
while($this->result = mysql_fetch_assoc($this->query))
{
$i = 1;
foreach ($this->result as $k => $v)
{
$this->newarray = array ($i => ($this->result[$k]=>$this->result[$v], $this->result[$k]=>$this->result[$v], $this->result[$k]=>$this->result[$v], ....);
}
$i++;
}
所以我可以得到的最终数组是这样的:
$newarray = array( "first_row" =>
("$result[colA]" => "$result[value]",
"$result[colB]" => "$result[value]",
"$result[colC]" => "$result[value]");
所以我可以使用一次全部返回整个数组,我可以使用它:
echo $newarray[0]['colA'];
echo $newarray[3]['colA'];
我希望我能很好地解释我的问题。先感谢您