Inner Joins

Reply

Join Date: Nov 2008
Posts: 10
Reputation: theo19 is an unknown quantity at this point 
Solved Threads: 0
theo19 theo19 is offline Offline
Newbie Poster

Inner Joins

 
0
  #1
Oct 13th, 2009
  1. <?php
  2.  
  3. $host='localhost';
  4. $user='root';
  5. $pass='';
  6.  
  7. //establish database connection
  8. $conn=mysql_connect($host,$user,$pass) OR die('Unable to connect');
  9.  
  10. //SELECT database for USE
  11. mysql_select_db('acumenchain') OR die('Unable to select database!');
  12.  
  13.  
  14. $query2 = "SELECT tblclasslist.studentNo
  15. FROM acumenchain.tblclasslist
  16. JOIN acumenchain.tblregistration
  17. ON tblclasslist.studentNo = tblclasslist.studentNo";
  18.  
  19. $result = mysql_query($query2) OR die('Unable to execute Query' . mysql_error());
  20. $num = mysql_num_rows($result);
  21.  
  22.  
  23. //close connection
  24. mysql_close($conn);
  25.  
  26. ?>

database name : acumenchain
Under my tblclasslist is studentNo (primary key).
Under my tblregistration is studentNo (primary key) and pword
Under my tbllogin is studentNo (primary key) and pword.

Objectives:
  • I want that only students who are registered in the tblclasslist can register on tblregistration.
  • I want that only who are registered can log-in to my site using his/her studentNo and pword.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 799
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster
 
0
  #2
Oct 14th, 2009
Try this:
  1. $query2 = "SELECT tblclasslist.studentNo FROM acumenchain.tblclasslist JOIN acumenchain.tblregistration ON tblclasslist.studentNo = tblregistration.studentNo JOIN acumenchain.tbllogin ON tblclasslist.studentNo = tbllogin.studentNo AND tbllogin.studentNo = tblregistration.studentNo";
Does this give the desired result?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC