1

I am trying to show a sum result of a column name ref_com from wp_users table in my wordpress site.For this I have written following code but it is showing an Array text as output value.What's wrong I am doing? Below is my code

<?php 
     $result=$wpdb->get_results("SELECT sum(ref_com) as result FROM ".$wpdb->prefix."users WHERE referredby = '$username'");  
     echo $result; 
?>
2
  • You have an sql injection vulnerability. Commented Dec 15, 2017 at 8:03
  • how can i avoid this Commented Dec 15, 2017 at 8:10

2 Answers 2

2

The get_results function by default returns array of row objects. So if you just directly do echo $result it will print Array. Try to do echo $result[0]->result instead.

Sign up to request clarification or add additional context in comments.

Comments

1

loop through the array and echo the result

foreach($result as $r){

 echo $r->result;

}

Comments

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.