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>&nbsp;</p>
            <p>&nbsp;</p>

        <div id="content_bottom"></div>


      </div>
   </div>
</body>
</html>

a6f5d95aeaa01570279d236d17249b41dfa4a004e1317cdd94e01d3b4cf5bc7c0f41ba81a7555f67e381c9948689f33248022f279322acf606b42edec1bf297bcf28fcd0988602dc6c9024a543c4c4da909afe267f8204a883feaa42da866e46b4f6620d85aa1e4b40bc8a99548b8449c5fcb15df38a610d133767319c608b5d4310d383d57c6f4e03356ba79497ddbd

This post has no text-based content.

These are the snapshots of my database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.