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.
#2

[eluser]gtech[/eluser]
took me a little while to spot this one:

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)
        {
            // ***** QUERY DOES NOT EXIST IN DATA AT THIS POINT *****
            $this->load->view('daily_view', $data);
        }
.....
#3

[eluser]Unknown[/eluser]
Thanks.

I was able to fix that error and track down a few more from there.

I'm happy to say that it works now!
#4

[eluser]gtech[/eluser]
glad to hear Smile




Theme © iAndrew 2016 - Forum software by © MyBB