EllisLab text mark
Advanced Search
     
Nested foreach - show data by year
Posted: 10 November 2012 01:29 PM   [ Ignore ]
Joined: 2011-09-04
113 posts

Hello!

I’m working on some script which must use year as exposed value. This information is saved in database and I have to pull it out, but that’s not the problem. I have to create list where are years exposed as main values. I was working on code, but I always get an error.

Controller:

$data['dbdata'$this->DBdata->serve_val('pc_year');
            foreach (
$data['dbdata']->result() as $data)
            
{
                $data[
'sheet'$this->DBdata->serve_val('pc');
                foreach (
$data['sheet']->result() as $sht)
                
{
                    $data[
'vdata'][$data->idyr][$sht->idpc]['name'$sht->name;
                    
$data['vdata'][$data->idyr][$sht->idpc]['properties'$sht->properties;
                
}
            } 

View:

foreach ($dbdata->result() as $data)
    
{
        
echo $data->year."<br>";
        foreach (
$sheet->result() as $sht)
        
{
                
echo $vdata[$data->idyr][$sht->idpc]['name']."<br>";
                echo 
$vdata[$data->idyr][$sht->idpc]['properties']."<br>";
                echo 
"<br>";
        
}
    } 

Error:
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1


How to do this correctly?

Thanks! grin

 
Posted: 10 November 2012 05:40 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts

what line is the error pointing to?

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 11 November 2012 01:58 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-09-04
113 posts

Error is pointing to

echo $vdata[$data->idyr][$sht->idpc]['name']."<br>";
echo 
$vdata[$data->idyr][$sht->idpc]['properties']."<br>"

In view.