简体   繁体   中英

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. 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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM