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
https://forums.phpfreaks.com/topic/270708-user-specific-content/
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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.