Hello Everyone. I have created a database and linked it with my php page. I have created some users, now what i want is to display the different courses to different users. But when I am trying to apply a join query it is displaying all the courses from the courses table. Cn some one help me out?
that is my code which i am writing for it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>SlickRed | florida web design</title>
</head>
<body>
<?php
session_start();
$connection = mysql_connect('localhost','root','');
if(!$connection){
die("Database Connection Failed". mysql_error());
}
$select_db = mysql_select_db('hamdard_attendance');
if(!$select_db){
die("Database Connection Failed" . mysql_error());
}
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$query_one = "SELECT * FROM users WHERE user_name = '".$username."' AND user_pass = '".$password."'";
$result = mysql_query($query_one) or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1){
$_SESSION['username'] = $username;
}else{
echo "Invalid Login Credentials.";
}
}
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
}
?>
<div id="container">
<div id="header">
<h1 style="text-align:left">Quality Management<span class="off"> Cell</span></h1>
</div>
<div id="menu">
<ul>
<li class="menuitem"><a href="#">Home</a></li>
<li class="menuitem"><a href="#">Attendance</a></li>
<li class="menuitem"><a href="#">Courses</a></li>
<li class="menuitem"><a href="#">Settings</a></li>
</ul>
<a style="text-align:right" href="#">Logout</a>
</div>
</div>
<div id="content">
<div id="content_top"></div>
<div id="content_main">
<?php echo "<h2> Welcome ".$username."</h2>"?>
<?php
$connection = mysql_connect('localhost','root','');
if(!$connection){
die("Database Connection Failed". mysql_error());
}
$select_db = mysql_select_db('hamdard_attendance');
if(!$select_db){
die("Database Connection Failed" . mysql_error());
}
//if(isset($_POST['stdnt_name']) && isset($_POST['course_name']) && isset($_POST['stdnt_rfid_tag']) && isset($_POST['student_id']) && isset($_POST['course_id'])){
//$sname = $_POST['stdnt_name'];
//$cname = $_POST['course_name'];
//$rfid_code = $_POST['stdnt_rfid_tag'];
//$sid = $_POST['student_id'];
//$cid = $_POST['course_id'];
/*$query_two ="SELECT c.course_name, sa.st_classes_attempt FROM students s INNER JOIN student_attendance sa ON s.stdnt_rfid_tag = sa.st_id INNER JOIN courses c ON sa.c_name = c.course_name";
$result_attendance = mysql_query($query_two) or die(mysql_error());
while($row = mysql_fetch_array($result_attendance)){
echo "<br />";
echo $row['course_name']. " " . $row['st_classes_attempt'] ."<br/ >";
}*/
$query_three = "SELECT c.course_name, sa.st_classes_attempt FROM students s INNER JOIN student_attendance sa ON s.stdnt_rfid_tag = sa.st_id INNER JOIN courses c ON sa.c_name = c.course_name";
$result_attendance3 = mysql_query($query_three) or die(mysql_error());
while($row = mysql_fetch_array($result_attendance3)){
echo "<br />";
echo $row['course_name']. " " . $row['st_classes_attempt'] ."<br/ >";
}
/*$query_three = "SELECT sc.stdnt_name, sa.st_classes_attempt FROM students s INNER JOIN student_attendance sa ON s.stdnt_rfid_tag = sa.st_id";
$result_attendance2 = mysql_query($query_three) or die(mysql_error());
while($row = mysql_fetch_array($result_attendance2)){
echo "<br />";
echo "<h3> User Summary:</h3> <br />";
echo $row['stdnt_name']." = ".$row['st_classes_attempt']."<br/ >";
}
*/
?>
<p> </p>
<p> </p>
<div id="content_bottom"></div>
</div>
</div>
</body>
</html>