I have a foreach and then a foreach inside a foreach. The first foreach seems to work fine and I don't get any php errors. However in each subsequent foreach loop I get a Message: Undefined property: stdClass::$filename
error (replace filename with every single identifier). Can someone help me out and tell me what I'm doing wrong? Thanks
if($query = $this->db->get()){
foreach ($query->result() as $row)
{
$textable = $row->text_table;
}
$this->db->distinct('filename');
$this->db->select('location');
$this->db->from('TranslateData');
if($query1 = $this->db->get()){
foreach($query1->result() as $row1){
$this->db->select('string_id');
$this->db->select($textable);
$this->db->where('filename', $row1->filename);
$this->db->from('TranslateData');
$query2 = $this->db->get();
$xml = '<?xml version="1.0" encoding="utf-8" ?>'.PHP_EOL;
$xml .= '<data>'.PHP_EOL;
foreach($query2 as $row2){
$xml .= '<item>'.PHP_EOL;
$xml .= ' <name>'.$row2->string_id.'</name>'.PHP_EOL;
$xml .= ' <copy><![CDATA['.$row2->$textable.']]></copy>'.PHP_EOL;
$xml .= '</item>'.PHP_EOL;
}
$xml .= '</data>'.PHP_EOL;
$path = str_replace('/', '', $row1->location);
$this->save_xml($path, $row1->filename, $xml);
}
}
}