CodeIgniter Forums
How to get single value from $fields = $this->db->field_data($table); - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How to get single value from $fields = $this->db->field_data($table); (/showthread.php?tid=35980)



How to get single value from $fields = $this->db->field_data($table); - El Forum - 11-17-2010

[eluser]Julia Yan[/eluser]
------------models
$fields = $this->db->field_data($table);

foreach ($fields as $row){
if ($row->type=='string') $row->len = $row->len/3; //utf8
$rows[] = $row;
}
// the red code does not get value? how to make the right code?
$form_data = array(
'id' => array('type'=>'input', 'size'=>20,'maxlength'=>$field['id']->len,'value'=>$value['id'],'name'=>'id','id'=>'id','readonly'=>'readonly' ),
'name' => array('type'=>'input', 'size'=>20,'maxlength'=>$field['name']->len,'value'=>$value['name'],'name'=>'name','id'=>'name' )
)

PS field len from other class


How to get single value from $fields = $this->db->field_data($table); - El Forum - 11-17-2010

[eluser]smilie[/eluser]
Well, you have:

fieldS (note S at the end);

but in your form_data you are using field (note there is NO S at the end)?

Cheers,
Smilie


How to get single value from $fields = $this->db->field_data($table); - El Forum - 11-17-2010

[eluser]Julia Yan[/eluser]
[quote author="smilie" date="1290020393"]Well, you have:

fieldS (note S at the end);

but in your form_data you are using field (note there is NO S at the end)?

Cheers,
Smilie[/quote]

Thanks, would you please sample?


How to get single value from $fields = $this->db->field_data($table); - El Forum - 11-17-2010

[eluser]sqwk[/eluser]
'field' != 'fields'

Updated code:

Code:
$fields = $this->db->field_data($table);

foreach ($fields as $row){
        if ($row->type==‘string’) $row->len = $row->len/3; //utf8
        $rows[] = $row;
}

‘id’    => array(‘type’=>‘input’, ‘size’=>20,‘maxlength’=>$fields[‘id’]->len,‘value’=>$value[‘id’],‘name’=>‘id’,‘id’=>‘id’,‘readonly’=>‘readonly’ ),
‘name’  => array(‘type’=>‘input’, ‘size’=>20,‘maxlength’=>$fields[‘name’]->len,‘value’=>$value[‘name’],‘name’=>‘name’,‘id’=>‘name’ )



How to get single value from $fields = $this->db->field_data($table); - El Forum - 11-18-2010

[eluser]Julia Yan[/eluser]
[quote author="squawk" date="1290051510"]'field' != 'fields'

Updated code:

Code:
$fields = $this->db->field_data($table);

foreach ($fields as $row){
        if ($row->type==‘string’) $row->len = $row->len/3; //utf8
        $rows[] = $row;
}

‘id’    => array(‘type’=>‘input’, ‘size’=>20,‘maxlength’=>$fields[‘id’]->len,‘value’=>$value[‘id’],‘name’=>‘id’,‘id’=>‘id’,‘readonly’=>‘readonly’ ),
‘name’  => array(‘type’=>‘input’, ‘size’=>20,‘maxlength’=>$fields[‘name’]->len,‘value’=>$value[‘name’],‘name’=>‘name’,‘id’=>‘name’ )
[/quote]

Thanks lots