Nacho Sarmiento
Nacho Sarmiento

Reputation: 473

Show the number of points

I have a table called wp_points created in Wordpress with these fields:

point_ID (INT) example: 1
point_user_ID (INT) example: 1
point_accumulated (INT)

And I need to show the amount of points have any ID. I have this code but does not show me anything:

<?php 
global $wpdb; 

$milink = $wpdb->get_row("SELECT * FROM $wpdb->points WHERE point_user_ID = 1");
echo $milink->point_accumulated; 
?>

What am I doing wrong?

Thanks for your help!

Upvotes: 0

Views: 55

Answers (2)

Samuel Cook
Samuel Cook

Reputation: 16828

You need to call the table:

$milink = $wpdb->get_row("SELECT * FROM `wp_points` WHERE point_user_ID = 1");

if you wanted to find the SUM of points where the point_user_id equals a particular number, then you could use SUM(), although I don't know what column you are savings your points in, so in the example I'll just use points:

$milink = $wpdb->get_row("SELECT SUM(points) as points_accumulated FROM `wp_points` WHERE point_user_ID = 1");
echo $milink->points_accumulated; 

Upvotes: 3

kittycat
kittycat

Reputation: 15045

<?php 
global $wpdb; 

$milink = $wpdb->get_row("SELECT * FROM {$wpdb->points} WHERE point_user_ID = 1");
echo $milink->point_accumulated; 

?>

Upvotes: 2

Related Questions