I am fetching data from datatabase in Symfony 1.4.
The problem is that i am not able to access that array in the Success page using foreach
loop and print_r()
.
The error is
Warning: Invalid argument supplied for foreach().
But when I do same thing in the Action page after the Query is executed I am able to get the data using foreach()
and print_r($result)
.
Why I am not able to get that array in the success page?
The query and the loop I am using is below:
$birthSearchQuery = Doctrine_Query::create()->select('a.bir_le_reg,a.bir_le_dob,b.bir_le_district')
->from('BirthLegalInfo as a')
->innerJoin('a.BirthStatisticalInfo as b')
->Where('bir_le_reg_no IS NOT NULL')
->andwhere('bir_le_birth_state =' . $birthState)
->andwhere('bir_le_birth_district =' . $birthDistrict)
->andwhere('YEAR(bir_le_dob)=' .$birthFromYear);
$result = $birthSearchQuery->execute(array(), Doctrine::HYDRATE_SCALAR);
It is returning me a array of arrays using print_r($result)
like this
Array
(
[0] => Array
(
[bir_le_reg] => Delhi
[bir_le_district] => Delhi
[bir_le_dob] => 2015
)
[1] => Array
(
[bir_le_reg] => Delhi
[bir_le_district] => Delhi
[bir_le_dob] => 2014
)
[2] => Array
(
[bir_le_reg] => Delhi
[bir_le_district] => Delhi
[bir_le_dob] => 2015
)
)
The foreach loop I am using is as
foreach($result as $value){
echo $value['bir_le_district'];
echo '<br />';
echo $value['bir_le_reg'];
echo '<br />';
echo $value['bir_le_dob'];
}
To pass a variable to the template in symfony 1.x you should prefix it by $this->
.
In your case, you should do that:
$this->result = $birthSearchQuery->execute(array(), Doctrine::HYDRATE_SCALAR);
Then, in your template, you can call:
foreach ($result as $value) {
Without any problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With