php - WP - troubles with joining two tables -
i trying find @ internet answer, , found something, not :-)
i have 2 tables - wp_users & wp_usermeta. these 2 tables has same id (wp_users.id , wp_usermeta.user_id). want take email address wp_users , join nickname wp_usermeta.
i beginner in sql , helpful, if explain :-) thank :-)
<?php //i want tu print in echo user emails connected nicknames 2 separate tables - wp_users //and wp_user_meta. trying connect these tables "id" has these 2 tables same (inner join part) $teacher_table = "select wp_users.user_email, wp_usermeta.nickname wp_users,wp_usermeta inner join wp_usermeta on wp_users.id = wp_usermeta.user_id"; $results_table_main = $wpdb->get_results($teacher_table); foreach ($teacher_table $value){ echo $value; } ?>
the previous answers , comments issue primary problem here querying column not exist, wp_usermeta.nickname
this need do:
$teacher_table = "select wp_users.user_email, wp_usermeta.meta_value wp_users inner join wp_usermeta on wp_users.id = wp_usermeta.user_id wp_usermeta.meta_key = 'nickname'";
and measure rest of code, note returned variable object must accessed such.
$results_table_main = $wpdb->get_results($teacher_table); foreach ($results_table_main $value){ echo $value->user_email; echo $value->meta_value; }
Comments
Post a Comment