[eluser]gazza7364[/eluser]
HI
I have a problem with the following code, which has been working fine until I updated Ubuntu today. Not sure if this is the cause or not. I also had a warning about date(), with timezone which I have now fixed. These problems both happend after the update.
View
Code:
<div id="year_wrapper" class="ui-corner-all">
<h1>Year</h1>
<div id="year">
<? foreach ($years as $year) : ?>
<div class="year" ><?=$year->year?></div>
<? endforeach; ?>
</div>
I 'm getting Message: Undefined variable: year. Their is a onclick = getname( <?= $year->user_id ?>
but the post seems to remove it from the above code.
When I do
Code:
<?php echo '<pre>' . print_r($years) . '</pre>' ?>
from the view the array shows the data, as follows:-
Array ( [0] => stdClass Object ( [user_id] => 29 [s_name] => Bloggs [f_name] => Joe[year] => Year 10 [full_name] => Joe Bloggs [ad_no] => 5405 ) [1] => stdClass Object ( [user_id] => 1 [s_name] => bloggs [f_name] => Joe [year] => Year 11 [full_name] => Joe Bloggs [ad_no] => 5243 ) [2] => stdClass Object ( [user_id] => 730 [s_name] => Joe [f_name] => blogs [year] => Year 7 [full_name] => Joe Bloggs [ad_no] => 5959 ) [3] => stdClass Object ( [user_id] => 3 [s_name] => bloggs [f_name] => joe [year] => Year 8 [full_name] =>Joe Bloggs [ad_no] => 5734 ) [4] => stdClass Object ( [user_id] => 5 [s_name] => Bloggs [f_name] => Joe [year] => Year 9 [full_name] => Joe Bloggs [ad_no] => 5584 ) )
but nothing shows when i use the foreach in the view as shown at the top of this page.
Any idea.
Controller
Code:
$data['years'] = $this->it_model->get_year();
$this->load->view('it', $data);
Model
Code:
function get_year() {
$this->db->select();
$this->db->group_by('year');
$query = $this->db->get('user');
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
}
return $data;
}
Thanks in advance.