Specific User Data

Hello,

I am currently building a site with members page, admin panel etc… the issue I have now is that I can’t figure out how to display data for one user but not all of them. for an example: I have a section that gives the user the option to upload a document, but i want that document to show up on a section called “Pending Documents” just for them or whoever uploaded a document. that document should also be shown on their supervisor’s profile page with the following links next to it “Approve” or “Deny”. If they hit “approve” the document then passes to his/her “Pending Documents” section on their profile, with all that being said, the user that originally uploaded the document should be able to see who already “approved” or “denied” their document as it runs up the so called chain… I know this is a lot to ask for help with but I learn quick i just need a step in the right direction.

When a user logs in successfully, you create a session storing their user id like this:

[PHP]
$_SESSION[‘SESS_USERID’] = $row[‘userid’];
[/PHP]

That way, when you want to pull any data or store any data related to that user, you know their ID - so in your documents page, you would run the query based on the user id

[PHP]
$statement = $dbconn->prepare("
SELECT id, docTitle, docURL, date
FROM documents
WHERE userid = :userid
");

$statement->execute([
“:userid” => $_SESSION[‘SESS_USERID’]
]);

$results = $statement->fetchAll(PDO::FETCH_ASSOC);

foreach($results AS $row){
//Process data
}
[/PHP]

Thank you very much for that!

Sponsor our Newsletter | Privacy Policy | Terms of Service