Welcome Guest, Not a member yet? Register   Sign In
SELECT AS problem
#1

[eluser]Unknown[/eluser]
I am having difficult time with a SELECT statement in the controller such as

"SELECT listings.brup + listings.brdown + listings.brlower AS bedrooms"

Thats a fragment, the rest of the SELECT statement works fine.

My problem is that in the view I cannot seem to get the alias "bedrooms" to be recognized.

I get the message: Message: Undefined property: stdClass::$bedrooms

I am new to OOP and codeigniter. I am not so much asking for a solution as I am wanting to know were in the documentation SELECT AS statements are discussed.

Thanks,

Doug
#2

[eluser]wiredesignz[/eluser]
http://dev.mysql.com/doc/
#3

[eluser]tonanbarbarian[/eluser]
I suggest running the query exactly in something like phpMyAdmin first to confirm that your sql is correct
CodeIgniter will not have a problem was AS because I have done that myself.

I think the problem might be "listings.brup + listings.brdown + listings.brlower"
it may need to be in brackets or it may need to be a concat if these are strings
#4

[eluser]JayTee[/eluser]
[quote author="greenest" date="1197693042"]I am having difficult time with a SELECT statement in the controller such as

"SELECT listings.brup + listings.brdown + listings.brlower AS bedrooms"
[/quote]

First - you really shouldn't have any SQL in your controller - that's for the model! Smile

It looks like you're trying to use SQL to put the three field values together?

Try this:

"SELECT CONCAT(listings.brup,listings.brdowm,listings.brlower) AS bedrooms FROM..."

Once you run the query, it could be something like:

$yourPHPObject->bedrooms to get the concatenated value.




Theme © iAndrew 2016 - Forum software by © MyBB