Jump to content

really need some help


dannyone

Recommended Posts

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.