Reputation: 95
I am not able to access the while loop variable outside of the loop in CodeIgniter model
my model
$result=$this->db->query("SELECT * FROM product_categories where type='product'");
$result1 = $result->num_rows();
if($result1>0)
{
$outputfinal['value']='true';
$output[]='';
while ($e=$result->result_array()){
$output[]=$e;
}
}
print_r($output);
die();
if I tried to print. I am getting following error please help.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in
Upvotes: 0
Views: 1378
Reputation: 54831
$result->result_array()
already returns an array with all records from a query, there's no need to use while
:
$result=$this->db->query("SELECT * FROM product_categories where type='product'");
$result1 = $result->num_rows();
if($result1>0) {
$outputfinal['value'] = 'true';
$output = $result->result_array();
}
print_r($output);
die();
while ($e=$result->result_array())
always returns truthy
value and your loop runs endlessly, causing above-mentioned memory error.
Upvotes: 3