trg86 Posted November 15, 2012 Share Posted November 15, 2012 Hey there guys, I am trying to figure this out and thought I would post here for a little help/advice. I have been working on the project for several weeks now and I am now needing to add a new feature to my existing system, but I am not quite sure the angle I should take. The system I have already display's the same data for every user, which all comes from a form after it is submitted on the main website. My system also involves being able to edit/update the original data, as well as move it to a different page of the system, i.e. 'the archive'. Working much like a user being able to move it to the archive page (which all users can see), I am needing a user to be able to move an entry from the main page to a page only they will be able to see, not any other user. What would be the best way to go about this? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/270708-user-specific-content/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 15, 2012 Share Posted November 15, 2012 (edited) You would use a database table that associates the user_id with the content_id that he can access (one row for each user_id/content_id association.) You would JOIN this table with the table holding the content to limit the content that the query returns to the specific user_id. The following assumes your login system stores the current user's id in $_SESSION['user_id']. // a query that gets all the content that the current visitor can access - $query = "SELECT c.id,c.title,c.content FROM content c JOIN access_table a ON c.id = a.content_id AND a.user_id = {$_SESSION['user_id']}"; // a query that gets one specific row (the id of the content is in $id) that the current visitor can access - $query = "SELECT c.id,c.title,c.content FROM content c JOIN access_table a ON c.id = a.content_id AND a.user_id = {$_SESSION['user_id']} AND c.id = $id"; Edited November 15, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/270708-user-specific-content/#findComment-1392516 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.