[eluser]Ram Krishna[/eluser]
i am new in code igniter and having some problem in coding drop down for country names.i made some code in codeigniter that is giving errors
the Model is
Code:
<?php
Class User extends CI_Model
{
function country()
{
$this->db->select('id,country_name');
$query=$this->db->get('countries');
$data=array();
foreach($query->result_array() as $row)
{
$data[$row['id']]=$row['country_name'];
}
return ($data);
}
}
?>
and view is
Code:
<?php echo form_dropdown('country_name', $data); ?>
and controller is
Code:
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Signup extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->model('user');
$this->load-> helper('form');
$this->load->helper('url');
$data['country']=$this->user->country();
$this->load->vars($data);
$this->load->view('signup_view',$data);
}
}
?>
and on executing giving following errors -
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/signup_view.php
Line Number: 23
and
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331
Any one please help me or give me a working code for dropdown.