mysql PHP比较两个表中的值

Let's say I have two tables: "user" and "grade"

my "user" table looks like this:

id|username|password|email

my "grade" table looks like this:

studentid|names|exam1|exam2|...

I want to compare "id" column from the user table with "studentid" column from grade table. If the logged in user has an id 5 then I would need to pull out studentid 5 with "names, exam1, exam2" from the grade table and display it in html format. How do I do this?

Please help.

You need to JOIN both tables,

SELECT  a.*, b.*
FROM    user a
        INNER JOIN grade b
            ON a.ID = b.StudentID
WHERE   a.ID = 5

To further gain more knowledge about joins, kindly visit the link below:

Try this..

SELECT  names, 
        exam1, 
        exam2
FROM  grade g
   INNER JOIN user u
      ON u.id = g.studentid
WHERE u.id = 5