How can I get the value returned from the row() function in the database

#1
[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.

#2
[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;

#3
[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

#4
[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...

#5
[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;

#6
[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?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.