douweng5420 2013-12-13 19:15
浏览 58
已采纳

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

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. Where as when I checked the array content using print_r() it is showing all the values. 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
Where as output must be
ENGLISH GEOGRAPHY ACCOUNTANCY COMPUTER ECONOMICS
26            27                   31                       32                 33
I am able to see the values on top of the page due to print_r(); which is like this
26 27 31 32 33

Need some help on this problem why I am not getting all values

  • 写回答

2条回答 默认 最新

  • douliao5467 2013-12-13 19:17
    关注
    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?