1

I was looking for over 3 hours on the internet how to get data from stdclass Object and none of these solution I found worked.

So what I have is simple mysql query

$park = $wpdb->get_row("SELECT COUNT(1) FROM wp_richreviews WHERE review_status='1'");  

And then print it

if($park)
{
   print_r($park); 
} 

Then it will show this

stdClass Object ( [COUNT(1)] => 2 )

But I want to recieve just "2" and not the stdclass object bla bla..

can anyone help me please ? thank you!

1
  • Change print_r to echo ? Commented Mar 31, 2016 at 15:23

2 Answers 2

1

You have made life a little difficult for yourself by not giving the result column a nice easily accessible name

If you change your query so the column has a known name like this

$park = $wpdb->get_row("SELECT COUNT(1) as count 
                        FROM wp_richreviews 
                        WHERE review_status='1'");

then you have a nice easily accessible property called count

echo $park->count;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you this worked !:) Unfortunely it says I cannot accept your answer, but this worked ! thanks again
You have to wait 20 minutes I believe before you can accept an answer
1

Change your query to:

$park = $wpdb->get_row("SELECT COUNT(1) as count 
                        FROM wp_richreviews WHERE review_status='1'");

and get count value with something like $park['count'];

1 Comment

do you know please how? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.