Welcome Guest, Not a member yet? Register   Sign In
Problem with data in view (SOLVED)
#1

[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">

        &lt;? foreach ($years as $year) : ?&gt;
  <div class="year" >&lt;?=$year->year?&gt;</div>
&lt;? endforeach; ?&gt;

</div>

I 'm getting Message: Undefined variable: year. Their is a onclick = getname( &lt;?= $year->user_id ?&gtWink but the post seems to remove it from the above code.


When I do

Code:
&lt;?php echo '<pre>' . print_r($years) . '</pre>'  ?&gt;
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.
#2

[eluser]CroNiX[/eluser]
Code:
<div class="year" >&lt;?=$year->year?&gt;</div>

try putting a space after year and ?&gt;
#3

[eluser]gazza7364[/eluser]
[quote author="CroNiX" date="1383098499"]
Code:
<div class="year" >&lt;?=$year->year?&gt;</div>

try putting a space after year and ?&gt;
[/quote]

I did as you said but stii getting same problem.

This is waht I changed it to.

Code:
&lt;? foreach ($years as $year) : ?&gt;
  <div class="year">&lt;?=$year->year ?&gt; </div>
&lt;? endforeach; ?&gt;

I have tried putting the following code in the view and it gets the values out of the array.

Code:
&lt;?php

foreach ($years as $year) {
echo $year->year;
}  
?&gt;

Not sure why it will work this way and not the other.
I still need to get the other to work for formatting the page.


I have since found out, that other parts of the site are not working since I updated to ubuntu 13.10. Looks like its a ubuntu problem and not codeigniter. Going to reinstall ubuntu to see if this solves the problem.
#4

[eluser]InsiteFX[/eluser]
Try using full php tags and not short tags.
#5

[eluser]gazza7364[/eluser]
[quote author="InsiteFX" date="1383250930"]Try using full php tags and not short tags.
[/quote]

Hi after reinstalling ubuntu, I got the same errors.
So I decided to try the full php tags, which worked. I thought I would let everyone know how I solved the problem, then I saw your reply.

Is their a reason why the short tags don't work anymore, or a setting which needs correcting?

Thanks for your reply.
#6

[eluser]InsiteFX[/eluser]
Check your php.ini file and CI config for short tags




Theme © iAndrew 2016 - Forum software by © MyBB