05-03-2012, 09:49 PM
[eluser]selftaught[/eluser]
I have been trying to figure out how to populate a form_dropdown using the form helper but have had no luck.
Below are the pieces to my project. Any help is greatly appreciated.
controller
model
view
The menu is being created but each element is in its own select box.
Also below are the errors I am getting from PHP.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: views/trx_form.php
Line Number: 1
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/trx_form.php
Line Number: 1
I have been trying to figure out how to populate a form_dropdown using the form helper but have had no luck.
Below are the pieces to my project. Any help is greatly appreciated.
controller
Code:
<?php
class Site extends CI_Controller {
function contact_us()
{
$data['main_content'] = 'contact_us';
$this->load->view('template',$data);
}
function about_us()
{
$data['main_content'] = 'about_us';
$this->load->view('template',$data);
}
function trx_form()
{
$data['main_content'] = 'trx_form';
$this->load->view('template',$data);
$this->load->model('trx_model');
$data['query'] = $this->trx_model->get_markets();
$this->load->view('trx_form',$data);
}
}
model
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class trx_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_markets()
{
$sql = "SELECT DISTINCT AASwitch FROM audit.btseqp";
$query = $this->db->query($sql);
return $query->result();
}
}
Code:
<?php foreach($query as $market)
{
echo form_dropdown('shirts', $market, 'large');
}
?>
Also below are the errors I am getting from PHP.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: views/trx_form.php
Line Number: 1
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/trx_form.php
Line Number: 1