0

I am using Codeigniter and Datamapper for DB Query. My controller is as follows

function fetch_interested_in()
{
    $in = new Interested_in();      
    $in -> get();
    $interested_in = array();
    foreach($in -> all as $data)
    {
        $interested_in[$data -> in_id] = $data -> in_title;
    }
    return $interested_in;
}

And my view file is as follows

    <?php foreach($interested_in as $in)

                        echo form_checkbox('in_in[]', $in -> in_id); 

    ?>

There are 3 rows in my table called Interested_in. 2 columns are there and names are in_id and in_title. When I run the code I get the following error in page at 3 places one after another.

**

A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: views/poverview.php Line Number: 137

**

Please let me know where am I going wrong. I'll really be very thankful to you. Thanks in advance.

Shashi Roy
  • 323
  • 3
  • 7
  • 22

1 Answers1

1
<?php foreach($interested_in as $in)

                    echo form_checkbox('in_in[]', $in); 

?>

Is enough.

Your title/id is "saved" in $in and not $in->id_id.

But in your case I guess you want:

<?php foreach(array_keys($interested_in) as $id):

      echo '<label>'.$interested_in[$id].'</label>';
      echo form_checkbox('in_in[]', $id); 

      endforeach;
?>
Robin Castlin
  • 10,956
  • 1
  • 28
  • 44
  • Oh wow... Its working... Thanks a lot for the quick reply... One more small doubt is there. I want to display the title too... What do I've to write...? column name is in_title... Thanks in advance... – Shashi Roy May 24 '12 at 13:37
  • exactly. I could not keep my question in correct way. Sorry for that. You are right. But above code displays lebel 3 times and checkbox only for one time. – Shashi Roy May 24 '12 at 13:42
  • I want to display the checkbox adjacent to label. Thanks again for the quick reply. – Shashi Roy May 24 '12 at 13:45
  • you are just awesome. I must not be this much lazy. You are fantastic. Its working like magic... Thanks thanks Thanks thanks Thanks thanks a lot... – Shashi Roy May 24 '12 at 13:47