167
« on: April 27, 2011, 05:24:20 AM »
A little lesson about MySQL query.
when you are dealing with multiple tables in the same query, you must either use full table name or you can create short aliases.
In your first code:
//-----------------------------------------------------
//--- Show Profile ------------------------------------
//-----------------------------------------------------
// WBB Datenbank auslesen
$sql = "SELECT a.userID, a.posts
FROM ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
LEFT JOIN wbb1_1_user a ON (a.userID = ".get_user_table_field("u.", "user_id").")
WHERE c.user_id = $user_id
ORDER BY c.user_name ASC";
$result = $site_db->query($sql);
you are using two tables: USERS_TABLE and wbb1_1_user
For USERS_TABLE you chosen an alias "u" and for wbb1_1_user an alias "a", it's all good, but then all of sudden there is an unknown alias "c" comes into play: c.user_id and c.user_name
But that is not actual error that mysql is complaining but the structure of the whole line is incorrect:
FROM ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
Try something like this:
$sql = "SELECT a.userID, a.posts
FROM ".USERS_TABLE." u
LEFT JOIN wbb1_1_user a ON (a.userID = ".get_user_table_field("u.", "user_id").")
WHERE u.user_id = $user_id
ORDER BY u.user_name ASC";
$result = $site_db->query($sql);