CodeIgniter Forums

Full Version: How can I get the value returned from the row() function in the database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Namsu[/eluser]
This is basically from a row output on a database using CodeIgniter.
$total = $this->ticketquery->countArtistTotal();

I have used print_r to tell me the structure of the object:
stdClass Object ( [COUNT(artevtid)] => 13 )

I tried several ways of accessing it like an array [] and an object -> but can't find any luck.

El Forum

[eluser]WanWizard[/eluser]
This is because in your method you have manually created a count query.

Do something like
Code:
COUNT(artevtid) AS count

Then you can access the result as
Code:
$total->count;

El Forum

[eluser]Namsu[/eluser]
I have changed my query to what you said:

I have the code:

$total = $this->ticketquery->countArtistTotal();
$total->count;

But I still get this error:

Message: Undefined property: stdClass::$count

El Forum

[eluser]WanWizard[/eluser]
Maybe it's time to show us the contents of the countArtistTotal() method, so we don't have to guess to what it is exactly returning...

El Forum

[eluser]Namsu[/eluser]
[quote author="WanWizard" date="1281654464"]This is because in your method you have manually created a count query.

Do something like
Code:
COUNT(artevtid) AS count

Then you can access the result as
Code:
$total->count;
[/quote]

I changed my SQL statement to:

Code:
$sql = "SELECT COUNT(artevtid) AS quantity FROM artevt";

and to get the value by return I used this:

Code:
$total->quantity;

El Forum

[eluser]WanWizard[/eluser]
Yes? Which is what I suggested, and there's nothing wrong with that.

Whether this works or not depends on how you run your query, how you fetch the result, and how you return it to the caller. Hence, what is the code of your method?