[英]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.