JonYork
JonYork

Reputation: 1243

using query results in the same function that calls them

For some reason I am unable to use query results in the same function that calls them. Please see controller below and model and let me know where my issue is.

What breaks down is line 2 of controller, trying to concatenate query result contact_name and description_computer and saving it as variable name. I get the following error "Undefined variable: query" for both query results.

Using codeigniter.

Controller

function get_quarter_info($data)
{
    $data['query'] = $this->model->get_client_info($data);
    $data['name'] = $query['contact_name'] . " " . $query['description_computer'] . ".pdf";
    $html = $this->load->view('Quarter_info_view', $data, true);
    $pdf = pdf_create($html, '', false);
    write_file($data['name'], $pdf);
    $this->index();

}

Model

function get_client_info($data)
{
    $query = $this->db->get_where('subscriber_report', array('client_number'=> $data['client_number']));
    return $query->row_array();
}

Upvotes: 0

Views: 82

Answers (2)

Zomxilla
Zomxilla

Reputation: 467

You should probably use $query instead of $data['query]. The data array is used to pass data to your view.

Upvotes: 3

cwallenpoole
cwallenpoole

Reputation: 81998

You're not assigning a value to $query in get_quater_info. Instead, you're assigning the value to $data['query'];

Try this instead:

$query = $data['query'] = $this->model->get_client_info($data);

Upvotes: 2

Related Questions