[split] How to echo an array - oscar1925 - 03-06-2018
Masters could you solve this, how to echo this array using
<?php foreach ($data as $rows): ?>
<?php end foreach: ?>
i got this array from a var_dump in my model...
my model....
Code: public function sampleprocm($enrolid)
{
$sql = 'GET_STUDENT_SUBJECTLOADS_BY_ENROLID()';
$results = $this->multiple_result_array( $sql );
echo '<pre>';
var_dump($results);
echo '</pre>';
$sql = 'CALL GET_STUDENT_SUBJECTLOADS_BY_ENROLID('.$enrolid.')';
$resultss = $this->multiple_result( $sql );
echo '<pre>';
var_dump($resultss);
echo '</pre>';
// return $resultss;
return $resultss;
}
my controller..
Code: public function sampleproc()
{
$data=$this->sections_m->sampleprocm(13);
// var_dump($data);
$this->load->view('pages/registrar/gradingsheet2v', $data);
foreach($data as $key)
{
foreach($key as $value)
{
echo "(".$value->section." ".$value->subject." ".$value->loadid_id." ".$value->grade1." ".$value->grade2." ".$value->grade3." ".$value->grade4." ".$value->average.")";
}
}
}
the output:
Code: array(1) {
[0]=>
array(4) {
[0]=>
object(stdClass)#31 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(21) "Afro Asian Literature"
["loadid_id"]=>
string(2) "12"
["grade1"]=>
string(2) "80"
["grade2"]=>
string(2) "79"
["grade3"]=>
string(1) "0"
["grade4"]=>
string(1) "0"
["average"]=>
string(5) "39.75"
}
[1]=>
object(stdClass)#32 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(18) "Araling Panlipunan"
["loadid_id"]=>
string(1) "9"
["grade1"]=>
string(2) "90"
["grade2"]=>
string(2) "85"
["grade3"]=>
string(2) "75"
["grade4"]=>
string(2) "95"
["average"]=>
string(5) "86.25"
}
[2]=>
object(stdClass)#33 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(40) "Music, Arts, Physical Education, Health "
["loadid_id"]=>
string(2) "11"
["grade1"]=>
string(2) "81"
["grade2"]=>
string(2) "83"
["grade3"]=>
string(2) "89"
["grade4"]=>
string(2) "90"
["average"]=>
string(5) "85.75"
}
[3]=>
object(stdClass)#34 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(21) "Philippine Literature"
["loadid_id"]=>
string(1) "8"
["grade1"]=>
string(2) "88"
["grade2"]=>
string(1) "0"
["grade3"]=>
string(1) "0"
["grade4"]=>
string(1) "0"
["average"]=>
string(2) "22"
}
}
}
(Hinam-is Afro Asian Literature 12 80 79 0 0 39.75)(Hinam-is Araling Panlipunan 9 90 85 75 95 86.25)(Hinam-is Music, Arts, Physical Education, Health 11 81 83 89 90 85.75)(Hinam-is Philippine Literature 8 88 0 0 0 22)
i was trying to retrieve data using a mysql procedure... and that is the output from var_dump.
i used to return data using the usual
return $query->result();
but now no result..
RE: [split] How to echo an array - Muthusamy - 03-06-2018
(03-06-2018, 12:00 AM)oscar1925 Wrote: Masters could you solve this, how to echo this array using
<?php foreach ($data as $rows): ?>
<?php end foreach: ?>
i got this array from a var_dump in my model...
my model....
Code: public function sampleprocm($enrolid)
{
$sql = 'GET_STUDENT_SUBJECTLOADS_BY_ENROLID()';
$results = $this->multiple_result_array( $sql );
echo '<pre>';
var_dump($results);
echo '</pre>';
$sql = 'CALL GET_STUDENT_SUBJECTLOADS_BY_ENROLID('.$enrolid.')';
$resultss = $this->multiple_result( $sql );
echo '<pre>';
var_dump($resultss);
echo '</pre>';
// return $resultss;
return $resultss;
}
my controller..
Code: public function sampleproc()
{
$data=$this->sections_m->sampleprocm(13);
// var_dump($data);
$this->load->view('pages/registrar/gradingsheet2v', $data);
foreach($data as $key)
{
foreach($key as $value)
{
echo "(".$value->section." ".$value->subject." ".$value->loadid_id." ".$value->grade1." ".$value->grade2." ".$value->grade3." ".$value->grade4." ".$value->average.")";
}
}
}
the output:
Code: array(1) {
[0]=>
array(4) {
[0]=>
object(stdClass)#31 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(21) "Afro Asian Literature"
["loadid_id"]=>
string(2) "12"
["grade1"]=>
string(2) "80"
["grade2"]=>
string(2) "79"
["grade3"]=>
string(1) "0"
["grade4"]=>
string(1) "0"
["average"]=>
string(5) "39.75"
}
[1]=>
object(stdClass)#32 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(18) "Araling Panlipunan"
["loadid_id"]=>
string(1) "9"
["grade1"]=>
string(2) "90"
["grade2"]=>
string(2) "85"
["grade3"]=>
string(2) "75"
["grade4"]=>
string(2) "95"
["average"]=>
string(5) "86.25"
}
[2]=>
object(stdClass)#33 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(40) "Music, Arts, Physical Education, Health "
["loadid_id"]=>
string(2) "11"
["grade1"]=>
string(2) "81"
["grade2"]=>
string(2) "83"
["grade3"]=>
string(2) "89"
["grade4"]=>
string(2) "90"
["average"]=>
string(5) "85.75"
}
[3]=>
object(stdClass)#34 (9) {
["student"]=>
string(2) "17"
["section"]=>
string(8) "Hinam-is"
["subject"]=>
string(21) "Philippine Literature"
["loadid_id"]=>
string(1) "8"
["grade1"]=>
string(2) "88"
["grade2"]=>
string(1) "0"
["grade3"]=>
string(1) "0"
["grade4"]=>
string(1) "0"
["average"]=>
string(2) "22"
}
}
}
(Hinam-is Afro Asian Literature 12 80 79 0 0 39.75)(Hinam-is Araling Panlipunan 9 90 85 75 95 86.25)(Hinam-is Music, Arts, Physical Education, Health 11 81 83 89 90 85.75)(Hinam-is Philippine Literature 8 88 0 0 0 22)
i was trying to retrieve data using a mysql procedure... and that is the output from var_dump.
i used to return data using the usual
return $query->result();
but now no result..
@oscar1925
you can echo an array by the below code. Hope it will help for you.
Code: $test =Array( "0" => Array
(
"0" => (Object)
[
"PRO_PRICE_CODE" => "AAA001001",
"PRO_MST_NM" => "Promo Air Asia",
"PRO_AMT_CUST" => "65000.00"
],
"1" => (Object)
[
"PRO_PRICE_CODE" => "AAAnghngng001001",
"PRO_MST_NM" => "Asia Airlines",
"PRO_AMT_CUST" => "55000.00"
]
)
);
foreach ($test as $key => $value) {
foreach ($value as $key1 => $value1) {
echo $value1->PRO_PRICE_CODE;
}
}
Thanks
Muthu
|