![]() |
Please help me to display count values returned from a database on form drop down - 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: Please help me to display count values returned from a database on form drop down (/showthread.php?tid=58934) |
Please help me to display count values returned from a database on form drop down - El Forum - 08-06-2013 [eluser]Unknown[/eluser] hi guys i am new in code ignitor i have a challenge for displaying values pulled from a database. i need data to be shown in form dropdown like this chicago (3) los angels (5) lagos (9) dubai (4) here is my model <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Fetch_data extends CI_Model { public function __construct() { parent:: __construct(); } function getloc() { $query = $this->db->query(' SELECT location, COUNT(*) FROM houseforrent GROUP BY location '); return $query->result(); } } here is my controller <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Main extends CI_Controller { function index() { $this->load->model('fetch_data'); $dat = $this->fetch_data->getloc(); $data['recs'] = $dat; $data['main_view'] = 'home'; $this->load->view('includes/contents',$data); } } here is my view <?php echo form_open('main/bylochouserent'); $submit = array ( 'name' => 'submit', 'value' => 'Find' ); foreach($recs as $da): $ona[$da->location] = $da->location . " ".$da[count('*')] = $da[count('*')]; endforeach; $di = "style = height :12 width : 20"; echo form_dropdown('street',$ona, 'sinza',$di); echo form_submit($submit); echo form_close(); ?> Please help me to display count values returned from a database on form drop down - El Forum - 08-06-2013 [eluser]CroNiX[/eluser] SELECT location, COUNT(*) AS house_count FROM houseforrent GROUP BY location ... $ona[$da->location] = $da->location . " ".$da['house_count'] = $da['house_count']; Please help me to display count values returned from a database on form drop down - El Forum - 08-07-2013 [eluser]Unknown[/eluser] thank you mr cronix you saved my day. Please help me to display count values returned from a database on form drop down - El Forum - 08-07-2013 [eluser]sv3tli0[/eluser] It will be good if you cache that count for few minutes... Few counts on each page loading will f*ck your DB ![]() |