[英]Accessing Arrays - multiple arrays
我有以下内容:
库MySQLi
$query = "SELECT company, AVG(q1) AS high_1 FROM tresults;"
$query .= "SELECT company, AVG(q2) AS high_2 FROM tresults;"
Var转储
array(2) { ["company"]=> string(8) "7yh6t5rf" ["high_1"]=> string(10) "7.65498709" }
array(2) { ["company"]=> string(8) "de4r5tgh" ["high_2"]=> string(10) "9.12375681" }
码
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_assoc()) {
for ($p=1; $p<=20; $p++)
{
echo"
<td class='a25'>";
echo number_format($row["high_".$p],2);
echo"</td>";
}
$result->free();
}
} while ($mysqli->next_result());
}
/* close connection */
$mysqli->close();
产量
<td class='a25'>7.65</td><td class='a25'></td>
基本上,我遇到的问题是,上面的代码仅回high_1
而不是high_2
。
我无法理解为什么会这样。 欢迎任何建议和反馈。
如果已实现,请尝试使用fetch array而不是fetch_assoc
函数,并且可以通过选择索引访问结果行
while ($row = $result->fetch_array()) {
echo "<td class='a25'>",
number_format($row[1],2),
"</td>";
$result->free();
}
我无法解决问题。
因此,我使用的解决方案是将所有内容简单添加到可以在while loop
之外使用的单个数组中的一种:
while ($row = $result->fetch_assoc()) {
$array[] = $row;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.