I think I'm just one step away from making this works but I need help in how to tie A & B together.
I've made a page within the WordPress structure. Since it's within WordPress, users will already be logged in and I am able to do things like display their username and other things. Without going through all the code, here's how I display the user's WordPress display name (which I will try to use later):
[code=php]get_currentuserinfo();
echo 'User display name: ' . $current_user->display_name . "\n";[/code]
Even though I don't make any call to the WordPress database myself, lets call that database A. Then I have my own custom, single-table database that has no relation to WordPress at all. Lets call that database B. On this same page I created (within WordPress) I am able to call database B and display content from it. This database is a directory of member's data, with one row being for each person. One of those data fields is a copy of each person's WordPress display name so I can hopefully match up the two databases.
[code=php]$db = mysql_connect("localhost", "XXXX", "XXXX");
mysql_select_db("DATABASENAME",$db);
$query = "SELECT * FROM brotherhood ORDER BY lastname";
$result = mysql_query ($query);
if (@mysql_num_rows($result))
{
print "<table border=\"1\" >\n";
print "<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Copy of WordPress Display Name</td>
</tr>\n";
while($row = mysql_fetch_array($result)) {
print "<tr>\n";
print "<td>".$row['firstname']."</td>\n";
print "<td>".$row['lastname']."</td>\n";
print "<td>".$row['wp_user']."</td>\n";
print "</tr>\n";
}
print "</table>\n";
} else { echo "<p>Sorry, no records were found!</p>"; }[/code]
And this code above works just fine (although I shortened the real display to just three fields for simplicity). So on the same page, I am able to output the logged-in user's display name (from database A (WordPress)), and later on I can also output all data from database B (custom).
Now I just want to know simply how to use a variable from the first database to specify/limit the output of the second database. What I want to do is to display only the one row of data from my custom database B (like firstname, lastname, and wp_user) but only where "wp_user" matches the "$current_user->display_name" value of the logged-in user. I tried several times but nothing worked because I don't really know what I'm doing. Can anybody please help me figure out how to do this?