2012-05-24 204 views
0

我使用笨和DataMapper的为DB查询生成Dyanmic复选框困难。我的控制器如下获得从数据库

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; 
} 

而且我认为文件如下

<?php foreach($interested_in as $in) 

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

    ?> 

有3排在我的表叫Interested_in。 2列在那里,名字是in_id和in_title。当我运行代码时,我在下面的3个地方接连发生了以下错误。

**遇到

一个PHP错误严重性:通知消息:试图让非目标文件名的 属性:意见/ poverview.php行号:137

**

请让我知道我要去哪里错了。我会非常感谢你。提前致谢。

回答

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

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

?> 

就够了。在$in而不是$in->id_id

你的标题/ ID为 “保存”。

但在你的情况我想你想:

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

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

     endforeach; 
?> 
+0

哇哦......它的工作......非常感谢你的快速回复......还有一个小疑问是存在的。我也想显示标题...我要写什么......?列名是in_title ...在此先感谢... –

+0

检查第二段代码。准确地说是 –

+0

。我无法正确地保留我的问题。对不起。你是对的。但是,上面的代码只显示一次lebel 3次和复选框。 –