Jump to content

User-Specific Content


trg86

Recommended Posts

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! :)

Link to comment
Share on other sites

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 by PFMaBiSmAd
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.