SHARE
TWEET

Untitled

a guest Jun 20th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE users (
  2.   id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  3.   username varchar(100) NOT NULL,
  4.   rol varchar(100) DEFAULT NULL,
  5. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  6.  
  7.  
  8. CREATE TABLE subjects (
  9.   subject_id int(11) NOT NULL AUTO_INCREMENT,
  10.   subject text,
  11.   PRIMARY KEY (subject_id)
  12. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;
  13.  
  14.  
  15. CREATE TABLE users_subjects (
  16.   users_subjects_id int(11) NOT NULL AUTO_INCREMENT,
  17.   user_id_fk int(11),
  18.   subject_id_fk int(11),
  19.   FOREIGN KEY(user_id_fk) REFERENCES users(id),
  20.   FOREIGN KEY(subject_id_fk) REFERENCES subjects(subject_id),
  21.   PRIMARY KEY (users_subjects_id)
  22. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;
  23.      
  24. $sql = "SELECT *
  25. FROM users
  26. where rol = 'alumno'
  27. and id in (
  28.     select distinct u.id
  29.     from users u, users_subjects us, subjects e
  30.     where u.username='".$_SESSION['username']."'
  31.     and us.user_id_fk=u.id
  32.     and e.subject_id=us.subject_id_fk
  33. );";
  34.  
  35.  
  36. $sql = "SELECT *
  37. FROM users u
  38. JOIN users_subjects us ON (us.user_id_fk = u.id)
  39. JOIN subjects s ON (s.subject_id = us.subject_id_fk)
  40. WHERE u.username = '".$_SESSION['username']."'
  41. AND u.rol = 'alumno'";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top