Var Dump
var_dump($row);
输出
array(1) { ["company"]=> string(8) "ffr3e456" ["high_1"]=> string(8) "8.32465" }
array(2) { ["company"]=> string(8) "gg8751hw" ["high_2"]=> string(7) "7.66574" }
当前代码
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_assoc()) {
for ($p=1; $p<=2; $p++)
{
echo number_format($row["high_".$p],2);
以上代码显示high_1
但不显示high_2
。
如果需要,我如何将上述内容组合成一个数组?
和/或我如何echo
high_1
和high_2
?
感谢。
答案 0 :(得分:1)
好的,这里的问题是你有一个多查询。因此,当您获得$row
时,它只包含一个 high_x
值,这就是您无法在循环内迭代的原因。
要解决此问题,您可以简单地合并行,因为company
无关紧要且可以覆盖,这可能如下所示
$data = array();
while ($row = $result->fetch_assoc()) {
$data = array_merge($data, $row);
}
现在$data
应该/看起来像这样(不一定按此顺序,但不应该重要)
array(
'company' => '...',
'high_1' => '...',
'high_2' => '...',
...
)