[eluser]Unknown[/eluser]
Got a problem.
I'm trying to get a dropdown working from a list in a database. I get this error when trying to load the view.
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: views/daily_view.php
Line Number: 18
The code in the controller looks like this:
Code:
function input()
{
# Validations
$this->load->library('validation');
$rules['payment'] = "required";
$rules['date'] = "required";
$rules['paycust'] = "required";
$this->validation->set_rules($rules);
# Input and textarea field attributes
$data["payment"] = array('name' => 'payment', 'id' => 'payment');
$data["date"] = array('name' => 'date', 'id' => 'date');
$data["paycust"] = array('name' => 'paycust', 'id' => 'paycust');
if ($this->validation->run() == FALSE)
{
$this->load->view('daily_view', $data);
}
else
{
$payment = $this->input->post('payment');
$date = $this->input->post('date');
$paycust = $this->input->post('paycust');
$this->load->model('Daily_model','', TRUE);
$data['query'] = $this->Daily_model->list_customers();
$this->Daily_model->add_daily();
$this->load->view('daily_view', $data);
$this->load->view('dailysuccess');
}
}
and the view this:
Code:
<?php echo $this->validation->error_string; ?>
<?php echo form_open('daily/input'); ?>
<p><label for="payment">Amount: </label><br /><?php echo form_input($payment); ?></p>
<p><label for="date">Date: </label><br /><?php echo form_input($date); ?></p>
<?php
if($query->num_rows() > 0) {
foreach ($query->result() as $row):
$x = $x + 1;
$options[$x] = $row->CustName;
endforeach;
};
?>
<p><label for="paycust">Customer: </label><br /><?php echo form_dropdown('paycust', $options); ?></p>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
</div>
</body>
</html>
What am I doing wrong here?
Thanks.