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

4

1 回答 1

1

您需要将数据从控制器传递到视图。

当前您正在传递$data给视图,在该数组中为该行添加另一个字段。

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

这应该在视图中起作用

echo $row1->$title;

没有测试上面的代码 - 但它应该可以工作。

于 2012-11-06T18:09:23.463 回答