SQL query in WD_usermeta DB

0

I want to make a query in the Wordpress database because I am creating a page that does the following, according to the user who is registered, this has some referrals, the referrals when registering there is a custom field that is a sponsor which is added in the BBDD correctly in the wp_usermeta table.

The question is what the sql query would be to pick up the nickname of my referral and the type of user it is.

This query would be fine

  SELECT * 
   FROM wp_usermeta um1 
   WHERE um1.user_id IN ( SELECT um2.user_id FROM wp_usermeta um2 WHERE    um2.meta_key = 'id_patrocinador' and um2.meta_value = '"$patrocinador"')AND    um1.meta_key = 'nickname'

I put an image of the table wp_usermeta so you can see what the table is like

When doing the query in the database to know if it would be good or not, I get the results I want, now the next step is to save the nickname of the users that come in variables to print them on the screen.

    
asked by AitorUdabe 03.10.2017 в 11:06
source

1 answer

0

I put the final solution and with sample levels.

$query = "SELECT * 
FROM wp_usermeta um1 
WHERE um1.user_id IN ( SELECT um2.user_id FROM wp_usermeta um2 WHERE um2.meta_key = 'id_del_referido' and um2.meta_value = '".$patrocinador."')AND um1.meta_key = 'nickname'";

$results1 = mysqli_query($conn,$query) or die('ok');


while ($fila = mysqli_fetch_row($results1)) {
$query2 = "SELECT * 
FROM wp_usermeta um1 
WHERE um1.user_id IN ( SELECT um2.user_id FROM wp_usermeta um2 WHERE um2.meta_key = 'id_del_referido' and um2.meta_value = '".$fila[3]."')AND um1.meta_key = 'nickname'";
$results2 = mysqli_query($conn,$query2) or die('ok');
echo '<ul class="lista-nivel-uno">
<li>'.$fila[3].'</li>';
while ($fila2 = mysqli_fetch_row($results2)) {
echo '<ul class="lista-nivel-dos><li>'.$fila2[3].'</li></ul>
</ul>';
}
}
    
answered by 03.10.2017 в 18:07