Welcome Guest, Not a member yet? Register   Sign In
I need a help with dropdown list
#1

(This post was last modified: 10-29-2014, 09:25 AM by Maijane.)

[b]I need a help I am new in codeigniter I am create a capturing tool for member I want to create a dropdown list which includes

Country
State
Region
branch name
[/b]

here is my controller
/****MANAGE MEMBER*****/
function member($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
if ($param1 == 'create') {
$data['membership_no'] = $this->input->post('membership_no');
$data['first_names'] = $this->input->post('first_names');
$data['last_name'] = $this->input->post('last_name');
$data['initials'] = $this->input->post('initials');
$data['title'] = $this->input->post('title');
$data['id_number'] = $this->input->post('id_number');
$data['passport_no'] = $this->input->post('passport_no');
$data['birthday'] = $this->input->post('birthday');
$data['gender'] = $this->input->post('gender');
$data['phone'] = $this->input->post('phone');
$data['email'] = $this->input->post('email');
$data['address_1'] = $this->input->post('address_1');
$data['address_2'] = $this->input->post('address_2');
$data['address_3'] = $this->input->post('address_3');
$data['city'] = $this->input->post('city');
$data['province'] = $this->input->post('province');
$data['country'] = $this->input->post('country');
$data['postal_code'] = $this->input->post('postal_code');
$data['branch'] = $this->input->post('branch');
$data['tier'] = $this->input->post('tier');
$data['join_date'] = $this->input->post('join_date');
$data['expiry'] = $this->input->post('expiry');
$data['status'] = $this->input->post('status');
$data['discount'] = $this->input->post('discount');
$this->db->insert('member', $data);
$member_id = mysql_insert_id();
move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/member_image/' . $member_id . '.jpg');
$this->email_model->account_opening_email('member', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
redirect(base_url() . 'index.php?admin/member/', 'refresh');


}

function buildDropCities($member){
//set selected country id from POST
$id_country = $this->input->post('id',TRUE);

//run the query for the cities we specified earlier
$districtData['districtDrop']=$this->cities_countries_model->getCitiesByCountry($id_country);

$output = null;

foreach ($cityData['cityDrop']->result() as $row)
{
//here we build a dropdown item line for each query result
$output .= "<option value='".$row->id."'>".$row->City."</option>";
}

echo $output;

$page_data['countryDrop'] = $this->cities_countries_model->getCountries();
$page_data['page_name'] = 'member';
$page_data['page_title'] = get_phrase('manage_member');
$this->load->view('index', $page_data);

}



and here is my view

<div class="control-group">
<label class="control-label"><?php echo get_phrase('country');?></label>
<div class="controls">
<?php echo form_dropdown('countriesDrp', $countryDrop,'','class="required" id="countriesDrp"'); ?>
</div>
</div>

<div class="control-group">
<label class="control-label"><?php echo get_phrase('city');?></label>
<div class="controls">
<select name="cityDrp" $cityDrop id="cityDrp">
<option value="">Select</option>
</select>
</div>
</div>

please help

and here is my model

<?php
class cities_countries_model extends CI_Model {

public function __construct()
{
$this->load->database();
}

//fill your country dropdown
public function getCountries()
{
$this->db->select('id,Country');
$this->db->from('Countries');
$query = $this->db->get();

foreach($query->result_array() as $row){
$data[$row['id']]=$row['Country'];
}
return $data;
}

//fill your cities dropdown depending on the selected city
public function getCityByCountry($id_country=string)
{
$this->db->select('id,city');
$this->db->from('cities');
$this->db->where('id_country',$id_country);
$query = $this->db->get();

return $query;
}

}


I have attached more info
The first field load okay but the second one doesnt
Reply
#2

There are so many dont's in here that it would take forever to explain... But, just for the fun of it, you must first load the models before using them.
Reply
#3

Could you tell us if there's anything wrong with it? Are you getting any errors?
Reply
#4

i am new in codeigniter - the first one option for country work well but the second option doesnt load at all
Reply
#5

here is my model <?php
class cities_countries_model extends CI_Model {

public function __construct()
{
$this->load->database();
}

//fill your country dropdown
public function getCountries()
{
$this->db->select('id,Country');
$this->db->from('Countries');
$query = $this->db->get();

foreach($query->result_array() as $row){
$data[$row['id']]=$row['Country'];
}
return $data;
}

//fill your cities dropdown depending on the selected city
public function getCityByCountry($id_country=string)
{
$this->db->select('id,city');
$this->db->from('cities');
$this->db->where('id_country',$id_country);
$query = $this->db->get();

return $query;
}

}
Reply
#6

<?php
class cities_countries_model extends CI_Model {

public function __construct()
{
$this->load->database();
}

//fill your country dropdown
public function getCountries()
{
$this->db->select('id,Country');
$this->db->from('Countries');
$query = $this->db->get();

foreach($query->result_array() as $row){
$data[$row['id']]=$row['Country'];
}
return $data;
}

//fill your cities dropdown depending on the selected city
public function getCityByCountry($id_country=string)
{
$this->db->select('id,city');
$this->db->from('cities');
$this->db->where('id_country',$id_country);
$query = $this->db->get();

return $query;
}

}

here is my model
Reply
#7

(10-29-2014, 06:03 AM)FlevasGR Wrote: Could you tell us if there's anything wrong with it? Are you getting any errors?

The first field work but the second doesnt work
Reply
#8

here is my model

<?php
class cities_countries_model extends CI_Model {

public function __construct()
{
$this->load->database();
}

//fill your country dropdown
public function getCountries()
{
$this->db->select('id,Country');
$this->db->from('Countries');
$query = $this->db->get();

foreach($query->result_array() as $row){
$data[$row['id']]=$row['Country'];
}
return $data;
}

//fill your cities dropdown depending on the selected city
public function getCityByCountry($id_country=string)
{
$this->db->select('id,city');
$this->db->from('cities');
$this->db->where('id_country',$id_country);
$query = $this->db->get();

return $query;
}

}
Reply
#9

This should probably be in the "issues" or "best practices" area. Just sayin'
Reply
#10

(This post was last modified: 10-30-2014, 06:46 AM by InsiteFX.)

Place in helpers.
Code:
// --------------------------------------------------------------------

/**
* build_dropdown()
*
* Builds a select/options dropdown.
*
* @access    public
* @param    string    - the select css class id
* @param    string    - the select css class values
* @param    object    - the database object
* @param    string    - the selected option value
* @param    string    - the onchanged method
* @return    string    - the output string
*/
if ( ! function_exists('build_dropdown'))
{
    //                       id         class    name    array        selected         onchange
    function build_dropdown($id = '', $classes, $name, $dropdown, $selected_value, $onchange_method = '')
    {
        $output  = "<select id='$id' class='$classes' name='$name' $onchange_method>\n";

        foreach ($dropdown as $key => $text)
        {
            $output .= "<option value=\"" . $key . "\"";

            if ($key == $selected_value)
            {
                $output .= " selected";
            }

            $output .= ">" . $text . "</option>\n";
        }

        $output .= "</select>\n";

        return ($output);
    }
}
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB