Access a STD Object in PHP

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.
namsu55Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gtaglianiCommented:
if $this->ticketquery is not a null class do this:


echo "<pre>";
echo print_r( get_class_methods($this->ticketquery) , true );
echo "</pre>";


you will see a list with $this->ticketquery methods (or funtions).
0
namsu55Author Commented:
Its not a null class because I gave the print out of the value which was 13 and that is correct but anyway I done what you said.

Array
(
    [0] => __construct
    [1] => insertItem
    [2] => checkEventField
    [3] => insertEvent
    [4] => insertImage
    [5] => insertJunctionImage
    [6] => getMainCat
    [7] => getSubCatMusic
    [8] => getArtist
    [9] => countArtistTotal
    [10] => Model
    [11] => _assign_libraries
)
0
gtaglianiCommented:
sorry i was wrong. im not very sure what are u trying to get, but if you are trying to get the info of  "artevtid"

do what i said before but with the artevtid object to see its methods.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

namsu55Author Commented:
I'm trying to get the 13 value.

I get the print_r to tell me that this is the structure:

stdClass Object ( [COUNT(artevtid)] => 13 )

I am just not sure how I can grab the data.

I have tried:

echo $total->COUNT;
echo $total->COUNT->artevtid;;
echo $total->COUNT['artevtid'];
0
gtaglianiCommented:
ohh! great,

try this:

echo $total->[0];
or
echo $total->['COUNT'];
0
namsu55Author Commented:
Tried both gtagliani and they are syntax errors. Thanks for helping. Just trying to figure it out.
0
gtaglianiCommented:
or this echo $total->['artevtid'];
0
namsu55Author Commented:
I think $variable->[] is always a syntax array, cannot access the object using the array brackets.
0
gtaglianiCommented:
Are u sure that if you do:

$total = $this->ticketquery->countArtistTotal();
¿$total is not 13 there?.

i mean if u do this:

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

what happens?
0
namsu55Author Commented:
I get:

Severity: 4096

Message: Object of class stdClass could not be converted to string
0
namsu55Author Commented:
The actual database returned value is fine, which is 13. But I just cannot access the value.
0
gtaglianiCommented:
echo $total->artevtid ; ?
0
namsu55Author Commented:
Message: Undefined property: stdClass::$artevtid
0
gtaglianiCommented:
this is the solution i think:


echo $total->['COUNT(artevtid)'];  

0
namsu55Author Commented:
That is a syntax error:

Parse error: syntax error, unexpected '[', expecting T_STRING or T_VARIABLE or '{' or '$' in
0
gtaglianiCommented:
sorry wrong
0
gtaglianiCommented:
well, i didnt want to give u this, because is not clean but.....


foreach ( $total as $oneTotal )
{
      echo $oneTotal;
}
0
Ray PaseurCommented:
Please run this and post the output here:

var_dump( $this->ticketquery );
0
Slick812Commented:
greetings namsu55, , if you want to expose the non-static properties of an object you might try and use the PHP
get_object_vars  (object $object); function which returns an array of properites (key and value) of an object.

var_dump(get_object_vars  ($total));

you might also try this -
echo $this->ticketquery->artevtid;
and if it shows an integer value, you might try
echo $total[$this->ticketquery->artevtid];

0
namsu55Author Commented:
Hi Ray, that output is just too much for the screen and I am 100% sure the class returns the correct data shown by print_r. Slick 812 get_object_vars gives me an output of an array and the statements below didn't work.

In my SQL I changed the query to this as advised at Code Igniter forum to:

SELECT COUNT(artevtid) FROM artevt AS count

so now what gtagliani said works:

foreach ( $total as $oneTotal )
{
      echo $oneTotal;
}

So I think it was more of an SQL query problem, too complicated to access for my liking through an object.
0
gtaglianiCommented:
The problem is how php handles the return answer from de database to an object when in the db field object has a '(' or ')' in its name. try with this

SELECT COUNT(artevtid) as quantity FROM artevt AS count

Try to print_r the object again and the [COUNT(artevtid)] will be replaced with [quantity] so now u can

echo $total->quantity(i think xD);

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
namsu55Author Commented:
Gtagliani: That worked. I reduced the SQL statement to:  "SELECT COUNT(artevtid) AS quantity FROM artevt". But out of curiosity. If Print_r was showing the 13 value, how could I have accessed that. I tried several ways all which didn't work.
0
Ray PaseurCommented:
"If Print_r was showing the 13 value, how could I have accessed that."

If you produced the var_dump() that I asked for above, I would have been able to show you this, and more.  Sorry you didn't feel that was appropriate.  I use it all the time, to very good effect.

In the future you may want to set up smaller test cases so that you feel comfortable engaging in the kind of dialog that EE is best for.  Good luck with your project, ~Ray
0
namsu55Author Commented:
Hi Ray I would make the old query again in a short while and do the dump on a file. I would like to learn something about that inner array type of object.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.