Welcome Guest, Not a member yet? Register   Sign In
Problem Passing Query
#1

[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 />&lt;?php echo form_input($payment); ?&gt;</p>
<p><label for="date">Date: </label><br />&lt;?php echo form_input($date); ?&gt;</p>
&lt;?php
    if($query->num_rows() > 0) {
        foreach ($query->result() as $row):
            $x = $x + 1;
            $options[$x] =  $row->CustName;
        endforeach;
    };
?&gt;
<p><label for="paycust">Customer: </label><br />&lt;?php echo form_dropdown('paycust', $options); ?&gt;</p>
&lt;?php echo form_submit('submit', 'Submit'); ?&gt;
&lt;?php echo form_close(); ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;



What am I doing wrong here?

Thanks.


Messages In This Thread
Problem Passing Query - by El Forum - 11-14-2007, 12:46 PM
Problem Passing Query - by El Forum - 11-14-2007, 01:55 PM
Problem Passing Query - by El Forum - 11-14-2007, 02:19 PM
Problem Passing Query - by El Forum - 11-14-2007, 02:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB