0

I am Creating a Online Course System so i created the following tables

Table Name = Users

 -Columns:
       1.userid
       2.full name
       3.email
       4.user
       5.password

Table Name = Stundents

  -Columns:
       1. stundentid
       2. userid
       3. idcourse
       4. active

Table Name = Courses

     -Columns:
          1. idcourse
          2. coursename
          3. courseimage
          4. courselink
          5. courseactive

What i need its to get all the information from the table courses and the table students where idusuario=$iduser

$iduser=$_SESSION["iduser"];

The thing is i need all stundent table data that has and especific userid and than grab the courseid fomr that table and than get the information of the courses from courses table where courseid its on the courseid from the students table

i need to validate that the user is suscribed to a course so i can show it up on his profile menu.

My english is bad, hopefully you can understan well. Thanks

1 Answers1

0

Use JOIN:

SELECT *
FROM Stundents
INNER JOIN Courses ON Courses.idcourse = Stundents.idcourse
WHERE Stundents.userid = $iduser;
ALFA
  • 1,726
  • 1
  • 10
  • 19
  • Topicstarter offcource don't forget to protect this against SQL injections even when you think the variable source is safe like a `$_SESSION` because it's [not (post off me)](https://stackoverflow.com/questions/18262878/how-to-prevent-php-sessions-being-shared-between-different-apache-vhosts/18263063#18263063) explains how sessions can be (possibly) attacked on shared webhosting accounts when configured wrong – Raymond Nijland Mar 18 '19 at 12:15