I have a WordPress blog with obviously a WordPress database.
Database name: wordpress
The two tables communicating are wp_users
and wp_usermeta
.
The table usermeta
has columns user_id
, meta_key
, and meta_value
.
user_id meta_key usermeta
1 name mark
1 userurl mark.com
1 points 8
2 name luke
2 userurl luke.com
2 points 4
2 name frank
2 userurl frank.com
2 points 6
I would display the data on a specific page like this and ordered by points value desc:
Name: Mark
User Blog: mark.com
points: 8
Name: Frank
User Blog: mark.com
points: 6
Name: Luke
User Blog: luke.com
points: 4
I used a code like this but obviously wont work:
$sql =
"SELECT user_id, meta_key, meta_value" .
" FROM wp_usermeta" .
" WHERE meta_key IN ('name','userurl','points')" .
" ORDER BY meta_value DESC";
$usermeta = $wpdb->get_results($sql);
print("<ul>");
foreach ($usermeta as $post)
{
print('<li>' . $post->meta_value . '<br/>');
print('</li><br><br>');
}
print("</ul>");
you can probably do something like
try this
DEMO HERE
you should structure your table like that for better and easier insert and update and select.
and then do this query
EDIT:
Have you considered using 2 queries?
First one to get the order by points, the second to get the data? Then manipulate the data from both results to create a new ordered array?