0

first thank you for solving privious problems.
I am working on codeigniter . i am making signup form in which countries dropdown list is required. i am unable to make this drop down list with table country in my database.Can any one help me.

Edited by daniel36: n/a

3
Contributors
8
Replies
36
Views
5 Years
Discussion Span
Last Post by wesley1263
0

i am making drop down list with code igniter to display countries it is my controller code-

function index()
{
$this->load-> helper(array('form','url'));
$this->load->view('signup_view');
$this->load->model('user');
$data=$this->user->country();


}

and
this is my model file named user code-

function country()
{
$this->db->select('id','country_name');
$records=$this->db->get('countries');
$data=array();
foreach($records->result() as $row)
{
$data[$row->id] = $row->country_name;
}
return ($data);
}

and this is my view file code-

<?php echo form_dropdown('country_name', $country); ?>

It is giving following error

A PHP Error was encountered


Severity: Notice


Message: Undefined property: stdClass::$country_name


Filename: models/user.php


Line Number: 27

and

A PHP Error was encountered


Severity: Notice


Message: Undefined variable: country


Filename: views/signup_view.php


Line Number: 22



and



A PHP Error was encountered


Severity: Warning


Message: Invalid argument supplied for foreach()


Filename: helpers/form_helper.php


Line Number: 331

Edited by Nick Evan: Fixed formatting

1

First of all remember to use CODE to wrap data you post in the forums.
Second: this is wrong $this->db->select('id','country_name'); you should write $this->db->select('id, country_name'); otherwise country_name will be seen as second argument.

Check if this solves the problems. Bye.

0

First of all remember to use CODE to wrap data you post in the forums.
Second: this is wrong $this->db->select('id','country_name'); you should write $this->db->select('id, country_name'); otherwise country_name will be seen as second argument.

Check if this solves the problems. Bye.

the problem is not solved.

0

Change the controller function with this:

function index()
{
    $this->load->model('user');
    $this->load->helper(array('form','url'));
    $data['country']=$this->user->country();
    $this->load->view('signup_view',$data);
}

If you load the view before you collect data you will get an error, and you need also to send data array to the view, so you need to use a second parameter in the load->view as I wrote above. If you get new errors post them, bye.

0

Change the controller function with this:

function index()
{
    $this->load->model('user');
    $this->load->helper(array('form','url'));
    $data['country']=$this->user->country();
    $this->load->view('signup_view',$data);
}

If you load the view before you collect data you will get an error, and you need also to send data array to the view, so you need to use a second parameter in the load->view as I wrote above. If you get new errors post them, bye.

now it is giving the error
Fatal error: Can't use function return value in write context in C:\xampp\htdocs\signup\application\controllers\signup.php on line 14

0

And what you have on line 14? $data['country']=$this->user->country(); ?
If yes you may want to paste the updated user model code?

0

And what you have on line 14? $data['country']=$this->user->country(); ?
If yes you may want to paste the updated user model code?

Now it is giving to errror-

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: views/signup_view.php

Line Number: 24


And

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: helpers/form_helper.php

Line Number: 331

foreach loop is not working and undifined data view file is showing.thanks for replying.

0

Hello daniel36, you can do this:

in the your view:

foreach($data_db as $dt_db):
$drop[$dt_db->id] = $dt_db->name;
enforeach;

echo form_dropdown('name_dropdown',$drop);

Ready!...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.