
Originally Posted by
r937
yes, you can
how is the users_details tables related to the bulletins table?
Please have a look at the attached images in my first post :
the column 'uname' in users_details table holds the username which is inserted into the 'poster' column when a bulletin message is submitted. I'd like to retrieve the 'avatar' from 'users_details' where uname = poster
Hope I managed to explain....
In the meantime I made a solution without joining 3 tables in a mysql query with the help of PHP. I know this is the MySql forum, I just want to post my solution here, maybe someone will find it helpful...
So, a function has to be called inside the loop (I know this is not very elegant but it works) :
PHP Code:
while ($bulletins_rows = mysql_fetch_array($result_bulletins)) {
$database->selectAvatarFromDir($bulletins_rows['poster_uname']);
// echo the wanted rows here
}
and the function is :
PHP Code:
function selectAvatarFromDir($user_name) {
global $avatar_img_src;
$avatars_dir = $website_path."__data/users/avatars/";
$count = 0;
if(is_dir($avatars_dir)) {
if($handle = opendir($avatars_dir)) {
while(($file = readdir($handle)) !== false) {
$count++;
}
closedir($handle);
}
}
$dh = opendir($avatars_dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
for ($i=1; $i<=$count; $i++) {
$strippedName[$i] = preg_replace('/\d*(\..+)?/', '', $files[$i]);
$file_ext[$i] = substr($files[$i], strrpos($files[$i],".")+1);
if ($strippedName[$i] == $user_name) {
$avatar_img_src = $strippedName[$i].".".$file_ext[$i];
if ($avatar_img_src == "") { $avatar_img_src = "default_avatar.jpg"; }
}
}
} // end function selectAvatarFromDir
Anyway, I suppose it's more elegant way to join the tables with a query, so I'll definitely switch to that one if I manage to build the query (with your help of course).....
Bookmarks