0

Okay, so I'm grabbing the data I need properly from the database. However, how do I take the "echo data" and echo it as a variable in my view?

For example,

<? echo $row1->title; ?>

is not working when placed in the view.

Here's a portion of my controller:

// Pricing and package details insert from db
    $query = $this -> db -> query('SELECT title, price, number_sites, number_entries, white_label FROM pricing');

    $row1 = $query->row(0); // 0 grabs first row in table: Package 1         

    echo $row1->title;
    echo $row1->price;
    echo $row1->number_sites;

If you want to view the entire controller, check it here: http://codepad.org/4nRrywzl

1 Answer 1

1

You need to pass through the data from the controller to the view.

Currently you are passing $data to the view, add another field in this array for the row.

$data['row1'] = $row1;
$this->load->view('shared/header_view', $data); // or any other view

and this should work in the view

echo $row1->$title;

Not tested the code above - but it should work.

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks! I tried that originally, but I get an error: "Message: Undefined variable: row1" and "Message: Trying to get property of non-object" in the view.
Remember to assign the variable to the array you are sending to the view
The error you received on your earlier attempt and quoted in your comment was likely to have been caused by the variable not being assigned to the $data array.
I did that...I had the $data assigned to the load->view from before... codepad.org/4nRrywzl
you're wiping out the data array when you do $data = array(.... Try putting $data[row1] = $row1 after that statement. Also you should be making the database call in a model not in your controller. You can read about models here: codeigniter.com/user_guide/general/models.html
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.