dannyone Posted February 16, 2009 Share Posted February 16, 2009 iv been at this for about a week now and i still can't get my head around it. i need to link three tables together; Student, Course, Student_Course. i need to get Student.Student_ID, Course.course_id, Course.time_slot, Course.RoomName, Course.day AND Student.Student_ID=Student_Course.Student_ID and Course.course_id=Student_Course.course_id. the problem is, i also need to make this query specific to the user that has logged in, so Student_ID=$login. can some1 help me out an show me where i am going wrong? im really stuck $sql = new mysqli('localhost', '1', '2', 'tutorial'); $run = $sql->query("SELECT Student.Student_ID,Student_Course.Student_ID,Student_Course.course_id,Course.course_id,Course.time_slot,Course.RoomName,Course.day FROM Student,Student_Course,Course WHERE Student_ID=".$login." AND Student.Student_ID=Student_Course.Student_ID AND Student_Course.course_id=Course.course_id"); while($row = $run->fetch_object()) { $times[$row->time_slot][$row->day] = "Course: $row->course_id<br />Room: $row->RoomName"; } thanks in advance Danny Quote Link to comment Share on other sites More sharing options...
Brian W Posted February 16, 2009 Share Posted February 16, 2009 please use code tags.... What errors (if any) do you get? Possibly try: $run = $sql->query("SELECT Student.Student_ID,Student_Course.Student_ID,Student_Course.course_id,Course.course_id,Course.time_slot,Course.RoomName,Course.day FROM Student LEFT JOIN Student_Course ON Student.Student_ID=Student_Course.Student_ID LEFT JOIN Course ON Student_Course.course_id=Course.course_id WHERE Student_ID=".$login); I don't know whether or not your query would work, but I don't see how it would. But, mine has not been tested so it may not work either. If you have phpMyAdmin, run the query in there to debug if it doesn't work on your page (that is if you don't get error messages from that class). Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 SELECT s.Student_ID, c.course_id, c.time_slot, c.RoomName, c.day FROM Student AS s INNER JOIN Student_Course AS sc ON (s.Student_ID = sc.Student_ID) INNER JOIN Course AS c ON (c.course_id = sc.course_id) WHERE s.Student_ID = ? this should work... Are you sure that Student_ID is their login? Quote Link to comment Share on other sites More sharing options...
dannyone Posted February 16, 2009 Author Share Posted February 16, 2009 thankyou both for you replys, i have tried to use both of ur codes but i cant get them working :S below i have put how i am storing the Student_ID, i think i am storing it in .$login.?? but not 100% sure im a bit of a noob.. can you have a quick look an see if thats right please? //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Create query $qry="SELECT * FROM Student WHERE Student_ID=".$login." AND Password='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_STUDENT_ID'] = $member['Student_ID']; $_SESSION['SESS_FIRST_NAME'] = $member['FName']; $_SESSION['SESS_LAST_NAME'] = $member['LName']; $_SESSION['login'] = $login; session_write_close(); thanks again Danny Quote Link to comment Share on other sites More sharing options...
drisate Posted February 16, 2009 Share Posted February 16, 2009 i did'int check a lot but first off, $login = clean($_POST['login']); $password = clean($_POST['password']); On this line your cleaning the vars ... so from this point stop using $_POST and start using $login and $password Quote Link to comment Share on other sites More sharing options...
dannyone Posted February 16, 2009 Author Share Posted February 16, 2009 im really sorry but i dnt get what u mean by start using $login and $password, can you show me an example or point me in the right direction? should i stop using clean? thanks Danny Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.