Welcome Guest, Not a member yet? Register   Sign In
Please help me to display count values returned from a database on form drop down
#1

[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();
?>



Messages In This Thread
Please help me to display count values returned from a database on form drop down - by El Forum - 08-06-2013, 08:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB