wpdb help
-
I need some help with wpdb again. I have created a new database for members and am trying to extract certain values from that database. I can successfully access the database and retrieve some values, but the following code does not seem to work. The first echo for the number of rows works correctly as does the 2 echos for the user email.
The line that is extracting the member_id from the new table does not return any value. The SQL query string was copied directly from phpmyadmin where it correctly returns the value. I did edit the email address for this posting.
The fourth echo extracting the user_email from the _users database with a similar command works correctly. What have I missed?Thanks for any suggestions.
Also is it possible to enter the SQL query directly without using wpdb?
` global $wpdb;
$table_name = $wpdb->prefix . “club_members”;
$members = $wpdb->get_var( “SELECT COUNT(*) FROM $table_name” );
echo “<p>The number of rows in the member table is {$members}</p>”;/* Determine the logged in member from email address*/
global $current_user;
get_currentuserinfo();
echo “<p>’User email: $current_user->user_email'</p>”;$member_email = $current_user->user_email;
echo “<p>The member email is: {$member_email}</p>”;/* Find member_id (row number) in club_members database from email address*/
$tmp = $wpdb->get_var( “SELECT member_id FROM $table_name WHERE member_email=\’[email protected]\ ” );
echo “<p>Member ID is {$tmp}</p>”;$email = $wpdb->get_var(“SELECT user_email FROM wp_users WHERE user_login = ‘guest’ “);
// Echo the user’s email address
echo “<p>Guest email is {$email}</p>”;
- The topic ‘wpdb help’ is closed to new replies.