Active records for beginners...

Hello all,

Sorry to bother the forums, but I'm having a bit of a tricky time with the active record and "Objects" it returns... Currently i'd like to retrieve a single records, so i
function getmy ($id) {
         $q = $this->db->get_where('socialhubspot', array('company_id' => $id));
         if ($q->num_rows() > 0) {
             return $data;

in my controller i

and in my view i
<?php  $mydata = $row[0]; ?>

My god, i just know that can't be a proper way to go about this...

<?php $mydata = $row[0]; ?>

Think $row is now an object not an array!
do <ppre> print_r($row)</pre>

You can safely shorten your model method to this:
function getmy ($id)
    return $this->db->get_where('socialhubspot', array('company_id' => $id))->row();

row() method always returns only one row so you dont have to use "$q->row(0)".

now in the controller:

In view:
&lt;?php echo $row->somefield ?&gt;

thanks cahva!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.