CodeIgniter Forums
Some newbie Activerecords questions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Some newbie Activerecords questions (/showthread.php?tid=43495)



Some newbie Activerecords questions - El Forum - 07-13-2011

[eluser]visua[/eluser]
Hey all,

Sorry for the newbie questions! I'm writing a controller for a 'post detail' page, that only needs to request a specific table row via ID.

Here is my controller. When I echo out $val, I get the proper response - so I assume my active records query is wrong? Or maybe I'm not calling it correctly in the view file.

I also understand I should be doing this from the model, however I'm just prototyping and learning; and right now this is the less confusing way Wink


Controller
Code:
function test($val)
  {
    $data['test'] = $this->db->get_where('blog', array('id' => $val), 1, 0);
    $this->load->view('post_view', $data);
  }


View - I understand this is probably wrong, I shoulnd't have to foreach a single row.
Code:
<?php foreach($test->result() as $row):?>
      <li class="block">&lt;?=$row->$post_title?&gt;</li>
&lt;?php endforeach;?&gt;


Any help would be greatly appreciated! Thanks in advance.


Some newbie Activerecords questions - El Forum - 07-13-2011

[eluser]Unknown[/eluser]
Hi visua,

I am also new around here so I may be wrong but, if you posted your code correctly, you should get an error
in you view file.

It should be "$row->post_title" instead of "$row->$post_title". One to many "$" signs.

I'm not a native English-speaking person so please excuse me if I made any mistakes :-P