php - How to retrieve data which only belongs to a specified user? -


i got page called summary shows user list of exam took , how long spend, etc. trying pull data based on user id. if have person called simon , person called mark, don't want simon seeing marks data. show user have.

this function :

function get_student_summary () {     $data = array();      $result = mysql_query("select a.*,b.*,c.*,d.*,e.* mock_exam_quiz a, mock_exam_student_summary b, mock_exam_users c, mock_exam_questions d, mock_exam_category e a.quiz_id = b.exam_id , c.user_id = b.user_id , d.question_id = b.question_id , e.category_id = b.category_id");      while ($row = mysql_fetch_assoc($result)) {         $data [] = $row;     }      return $data; }  

this snippet of how user viewing exam details on summary page. screenshot

this image below screenshot of database table storing data. database screenshot. if @ user_id there 2 different user's , have mentioned want user see 1 belongs them. don't want show other user's data other users.

i sorry if have confused or not explained in detail problem, please ask if have questions. been stuck on problem past few days , appreciate guys.

what you'll have pass id through function , use id in query.

your function this:

function get_student_summary ($id) {     $data = array();      $result = mysql_query("select a.*,b.*,c.*,d.*,e.* mock_exam_quiz a, mock_exam_student_summary b, mock_exam_users c, mock_exam_questions d, mock_exam_category e a.quiz_id = b.exam_id , c.user_id = b.user_id , d.question_id = b.question_id , e.category_id = b.category_id , c.user_id='".$id"'");      while ($row = mysql_fetch_assoc($result)) {         $data [] = $row;     }      return $data; }  

you'll notice @ end of query put and c.user_id='".id"'. have not done php in long time, think should either using mysqli or pdo queries well.

edit:

so when do:

get_student_summary($id) $ryou should passing person's id in here. imagine clicks button when go page, pass through on button click page.


Comments