Welcome Guest, Not a member yet? Register   Sign In
Haven't Trouble Passing Variables To View
#1

[eluser]Barwick[/eluser]
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
Code:
<? echo $row1->title; ?>
is not working when placed in the view.

Here's a portion of my controller:

Code:
// 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;

I've done a bit of reading and googling...which lead me to doing this...but it's still not working (this is the full modified controller - different from above)

http://codepad.org/dkPBQtbL

Where am I going wrong?
#2

[eluser]b0ris55[/eluser]
Hard to say but you don't need row(0), row() automatically returns first row. If there is no results it's possible that your $row1 object is empty. After you set that object, in the next line, try outputting it via print_r($row1) to make sure everything you need is in there. Everything seems allright and should work.

B
#3

[eluser]Barwick[/eluser]
[quote author="b0ris55" date="1352252098"]Hard to say but you don't need row(0), row() automatically returns first row. If there is no results it's possible that your $row1 object is empty. After you set that object, in the next line, try outputting it via print_r($row1) to make sure everything you need is in there. Everything seems allright and should work.

B[/quote]

Thanks...echo's fine within controller. Adding it as a variable is the concern. This issue is KILLING me...lol
#4

[eluser]CroNiX[/eluser]
add a limit to your query
#5

[eluser]Barwick[/eluser]
[quote author="CroNiX" date="1352255494"]add a limit to your query[/quote]

Interesting. So adding a limit to AR would be:
Code:
$query = $this->db->get('pricing', 1);

This correct? If so, produces error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Subscription

Filename: views/subscribe.php

Line Number: 8


Which is this line in my view:
Code:
<? echo $row1->$title; ?>
#6

[eluser]Aken[/eluser]
$row1->$title is wrong. There is no second $. Should be $row1->title;

Also, I'd recommend opening your PHP tags fully, using <?php
#7

[eluser]Barwick[/eluser]
[quote author="Aken" date="1352256802"]$row1->$title is wrong. There is no second $. Should be $row1->title;

Also, I'd recommend opening your PHP tags fully, using <?php[/quote]

Agh!!! You're right man! I've been stewing over this for a while now. Couldn't figure out wtf I was going wrong. I could hug you man. lol

Between CroNIX and you, you two have been a huge help on here. I should be paying you guys... :p




Theme © iAndrew 2016 - Forum software by © MyBB