WordPress.org

Ready to get started?Download WordPress

Forums

display email, but for another user, not the user logged in (1 post)

  1. gopanthers
    Member
    Posted 3 years ago #

    Sorry if this is in the wrong forum category. Also sorry that I don't know all the correct terminology so I have to just describe everything very well.

    I'm working with custom php inside WordPress, that access a totally non-WP database that's on the same server. On custom pages within the WP structure I am able to displayed data from both the WordPress database and my custom database, based on who is currently logged in. This is possible because I have one field in my custom database (single table) that has an exact copy of each user's user_login, so all I have to do is call the database like this....
    $sql2 = "SELECT * FROM my_custom_table WHERE wp_user='$current_user->user_login'";

    and then display data like this...
    <?php echo $current_user->user_email ?>

    So far it's worked great for everything but now I need to do one thing that is different but very important, and I can't figure out how to do it. On a different custom page I display information about membership data from my custom table based on a value in the URL, like /info.php?id=65. Again this works great for almost all data, but because I didn't want redundancy of information, each member's email address is only stored in the WordPress database, as part of their login credentials. I'm having a heck of a time trying to figure out how to display data from the WordPress database, based on that id value from the URL. Since that value has no direct relation to the WP database I have to tie it together by a field in my custom database named wp_user, which exactly matches the wp_login field in the WordPress database. With me so far?

    Here's what I was trying.

    <?php
    $id=$_GET['id'];
    
    // query the WordPressDB
    $wp_server = "localhost";
    $wp_username = "XXXX";
    $wp_password = "XXXX";
    $wp_database = "XXXX";
    $wp_con = mysql_connect($wp_server, $wp_username, $wp_password);
    mysql_select_db($wp_database, $wp_con); 
    
    $wp_sql = "SELECT * FROM wp_users WHERE YYYYYYYYYYYYYYY";
    $wp_result = mysql_query($wp_sql);
    $wp_row = mysql_fetch_array($wp_result);
    
    echo $wp_row["user_email"];
    ?>

    Except the YYYYYYYYYYYYYY is how I need to tie the data from the two tables together. Previously that part said WHERE id=$id but that was when I was matching the id in the URL to the id in the custom table. Now I need to somehow make it do something like this...

    "get user_email from wp_users (in wordpress_database) WHERE wp_user from custom_table (in custom_database) matches wp_login (in wordpress_database)"

    Can this be done? If not the way I was trying, I want to get a user's email address based on their id from a different database. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.