Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 访问阵列-多个阵列_Php_Arrays_Mysqli - Fatal编程技术网

Php 访问阵列-多个阵列

Php 访问阵列-多个阵列,php,arrays,mysqli,Php,Arrays,Mysqli,我有以下资料: MySQLi 变量转储 代码 输出 基本上,我遇到的问题是,上面的代码只是echo的high_1,而不是high_2 我无法理解为什么会发生这种情况。欢迎任何建议和反馈。如果已经实现了fetch_assoc函数,请尝试fetch array而不是fetch_assoc函数,您可以通过选择索引访问结果行 while ($row = $result->fetch_array()) { echo "<td class='a25'>",

我有以下资料:

MySQLi

变量转储

代码

输出

基本上,我遇到的问题是,上面的代码只是echo的high_1,而不是high_2


我无法理解为什么会发生这种情况。欢迎任何建议和反馈。

如果已经实现了fetch_assoc函数,请尝试fetch array而不是fetch_assoc函数,您可以通过选择索引访问结果行

    while ($row = $result->fetch_array()) {
      echo "<td class='a25'>", 
           number_format($row[1],2),
           "</td>"; 
      $result->free();
    }

我还没能解决这个问题

因此,我使用的解决方案是简单地将所有内容添加到一个数组中,我可以在while循环之外使用该数组:


在这里,您重复了高风险转储$row;并检查您是否真的在结果记录中得到了它。@MoeedFarooqui他这样做:echo number_format$row[high.$p],2;要尝试回显它…@Homer\u J-您不能在foreach循环中执行此操作,在该循环中,您增加一个整数值变量来回显high\u*?var\u转储$row的是什么;给出?感谢您的反馈,但我需要使用fetch_assoc。如果您只有2种类型的数组键,那么您可以使用echo isset$row[high_1]$行[high_1]:$row[high_2]再次感谢,但是,正如您从问题中的代码中看到的,我有20个键要循环:for$p=1$P
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>
    while ($row = $result->fetch_array()) {
      echo "<td class='a25'>", 
           number_format($row[1],2),
           "</td>"; 
      $result->free();
    }
while ($row = $result->fetch_assoc()) {
    $array[] = $row;
}