silverglade Posted July 6, 2011 Share Posted July 6, 2011 Hi, I have a pretty decent newbie gallery now, just bare bones functionality, my next step I would like to do is take the images in a gallery collection, and link them to a user in the database, so that each user has their own gallery seen only to them. I don't know how I would do that. My user table fields are "user name" "name" "password" "email". I also have a gallery table. So I know I have to somehow, after the user logs on, encode any uploaded images with some unique identifier, then check that identifier every time a user enters the gallery page.. Any help greatly appreciated on how to approach this. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/241181-trying-to-link-specific-gallery-images-to-users-in-a-database/ Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2011 Share Posted July 6, 2011 Insert the primary key from the user's record in the users table as the owner id of each image in the gallery table. Then you'd just select the images for display that match the logged in user's id. Quote Link to comment https://forums.phpfreaks.com/topic/241181-trying-to-link-specific-gallery-images-to-users-in-a-database/#findComment-1238851 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 Thank you Pikachu2000 I will try to do it. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/241181-trying-to-link-specific-gallery-images-to-users-in-a-database/#findComment-1238859 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 I added a field in the images (gallery) table. I called it "gallery_user". I want that to hold the user "id" primary key value when I upload each image. But I don't know how to do it. I don't know how to put like , "upload this, and make the user "id" equal to the "gallery_user" field. Please any more help greatly appreciated. For displaying the images, I somehow have to check "id" against "gallery_user" . but I don't know enough sql for that. lol. something like , output image WHERE gallery_user == id, but I know I can't do that in sql , I think. sorry. EDIT: It looks like I use the JOIN command, not sure yet. Quote Link to comment https://forums.phpfreaks.com/topic/241181-trying-to-link-specific-gallery-images-to-users-in-a-database/#findComment-1238862 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 no, I don't know still Quote Link to comment https://forums.phpfreaks.com/topic/241181-trying-to-link-specific-gallery-images-to-users-in-a-database/#findComment-1238866 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 ok this is as far as I got. It doesn't work, does anyone know why please? thanks. $currentUser = $_SESSION['myusername']; $userId = mysql_query("SELECT id FROM users WHERE username = $currentUser");//get current session user name and get ID. mysql_query("INSERT INTO images (gallery_user) values ('$userId')");// insert current user id into gallery user. //all based on the session user name Quote Link to comment https://forums.phpfreaks.com/topic/241181-trying-to-link-specific-gallery-images-to-users-in-a-database/#findComment-1238883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.