简体   繁体   English

我如何在另一个PHP页面中显示所有数组值

[英]How can I display all the array value in another php page

I am trying to display the value of an array in which is passed from one php page to another php page, but I am getting only last element value. 我试图显示一个数组的值,其中从一个php页面传递到另一个php页面,但是我只得到最后一个元素值。 Where as when I checked the array content using print_r() it is showing all the values. 当我使用print_r()检查数组内容时,它会显示所有值。 This is where I need to the value to be displayed - 这是我需要显示的值的地方-

<tr class="bgcolor_02">
  <?php
    if(is_array($subject_array))
    {
    foreach($subject_array as $each_subject)
    {
  ?>
  <td width="9%"> <?php echo ucfirst($each_subject['es_subjectname']);?> </td>
  <?php } } ?>
</tr>
<tr>
  <?php
  $inc=0;
  foreach($subject_array as $each_subject)
  {
  ?>
  <td> <?php echo $array_roll[$inc]; ?> </td>
  <?php $inc++;
  }?>
</tr>

And here is the code from where values are fetched and passed - 这是从中获取和传递值的代码-

if(count($errormessage)==0)
{
  $cout=0;
  if(isset($classid))
  {
    $subject_array=$db->getRows("SELECT * FROM es_subject WHERE es_subjectshortname='".$classid."'");
    if(is_array($subject_array))
    {
       foreach($subject_array as $each_subject)
       {
      $array_subject[$each_subject['es_subjectid']]=$each_subject['es_subjectname'];

      $sub_id=$each_subject['es_subjectid'];
      $roll_array=$db->getRow("SELECT es_exam_detailsid FROM es_exam_details WHERE academicexam_id='".$exam_id."' AND subject_id='".$sub_id."'");               
          $array_roll[$cout]=$roll_array['es_exam_detailsid'];
      print_r($array_roll[$cout]."  ");
    }
      }
   }
}

By this code I am getting Output like this 通过此代码,我得到这样的输出
ENGLISH GEOGRAPHY ACCOUNTANCY COMPUTER ECONOMICS 英语地理会计计算机经济学
33 33
Where as output must be 作为输出必须在哪里
ENGLISH GEOGRAPHY ACCOUNTANCY COMPUTER ECONOMICS 英语地理会计计算机经济学
26 27 31 32 33 26 27 31 32 33
I am able to see the values on top of the page due to print_r(); 由于print_r(),我能够在页面顶部看到这些值; which is like this 就像这样
26 27 31 32 33 26 27 31 32 33

Need some help on this problem why I am not getting all values 在这个问题上需要一些帮助,为什么我无法获得所有价值

Had to tell exactly what is going on because of poor code formatting and non-meaningful variable names, but I am guessing your problem might lie here: 由于错误的代码格式和无意义的变量名,不得不确切说明正在发生的事情,但是我猜您的问题可能出在这里:

$array_roll[$cout]=$roll_array['es_exam_detailsid'];

You never change the value for $cout , so you are just continually overwriting the value and array index position 0. 您永远不会更改$cout的值,因此您将不断覆盖值和数组索引位置0。

foreach($subject_array as $each_subject)
       {
      $array_subject[$each_subject['es_subjectid']]=$each_subject['es_subjectname'];

      $sub_id=$each_subject['es_subjectid'];
      $roll_array=$db->getRow("SELECT es_exam_detailsid FROM es_exam_details WHERE     academicexam_id='".$exam_id."' AND subject_id='".$sub_id."'");               
          $array_roll[$cout]=$roll_array['es_exam_detailsid'];
      $cout++; //HERE YOU MUST HAVE++
    }

AND will be good. 并且会很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在另一个php页面上设置的php页面上显示cookie值 - How to display a cookie value on a php page that was set on another php page 如何在另一个php页面(包括包含GET请求的php页面)上显示超链接的GET输出 - How can i display GET output of a hyperlink on another php page (that includes the php page that contains GET request) 如何使用张贴到另一个PHP页面显示复选框数组键的值? - How to display value of checkbox array key using post to another php page? 我如何在php中显示所有行 - How I can display all rows in php 如何将函数的值从一页返回到PHP的另一页,并使用会话将其存储在数组中? - How to return a value of a function from one page to another page i php and store it in an array using session? 我如何使用php在另一个页面中显示单个记录的详细信息 - how can i Display individual records details in another page using php 如何在单击按钮时将会话值保存为数组并显示在另一页上? - How can I save session values as array on button click and display on another page? 我如何使用php从另一页的多个值中获取下一页的单个值 - how can i get single value at next page from multiple values in another page using php 如何使用PHP中的foreach循环将数组的一个元素添加到另一个数组的所有元素 - How can I add one element of array to all elements of another array using foreach loop in php Curl PHP:如何获取网页的所有内容并以浏览器的方式显示? - Curl PHP: How can I fetch all content of a web page and display it the way a browser does?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM