codeigniter - How to load database into helper and display in view with specific column -
footer_helper
<?php function get_gadget_footer() { //the database functions can not called within helper //so have explicitly load functions need in object //that call ci. use access regular stuff. $ci=& get_instance(); $ci->load->database(); //select required fields database //$ci->db->select('name, type, setting'); //tell db class criteria $ci->db->where('display', 'footer'); //supply table name , data $query = $ci->db->get('gadgets'); foreach($query->result() $row): $type['name'] = $row->name; $type['type'] = $row->type; var_dump($type); endforeach; return $type; } hi helper page. var_dump($type) returning me required result in form of array as:
var_dump($type)
array (size=2) 'name' => string 'quick links' (length=11) 'type' => string '<a href='www.facebook.com'>facebook</a><br> <a href='#'>twitter</a><br> <a href='#'>salyani</a><br> <a href='#'>b&w</a><br>' (length=123) array (size=2) 'name' => string 'social network' (length=14) 'type' => string '<a href='#'>facebook</a><br> <a href='#'>facebook</a><br> <a href='#'>facebook</a><br> <a href='#'>facebook</a><br>' (length=115) now in view page. want display specific record in div. record of name record of type .
since had done following:
view
<?php $this->load->helper('footer_helper'); $name = get_gadget_footer(); ?> <div id="footer"> <div id="footer_gadget_collection"> <?php foreach ($name $dat){ ?> <?php ?> <div id="footer_subgadget"> <div id='title'><?php echo $dat['name']; ?></div> <div id='description'><?php $dat['type']; ?> </div> </div> <?php } ?> but, giving me error. please me.
in helper restting name/type of array, not building it.
should like;
<?php //supply table name , data $query = $ci->db->get('gadgets'); $type = array(); foreach ($query->result() $row) { $type[] = array('name' => $row->name, 'type' => $row->type); } return $type;
Comments
Post a Comment