<?php
    session_start();
    include "dbConfig.php";

if (!$_SESSION["valid_user"])
        {
        // User not logged in, redirect to login page
      //  Header("Location: login.php");
        }


echo "<p>User ID: " . $_SESSION["valid_id"];
echo "<p>Username: " . $_SESSION["valid_user"];

    $sql    = "SELECT tbl_subject.SubjectID, tbl_subject.SubjectDesc, studentsubjectgrade.Finals
               FROM tbl_subject 
               INNER JOIN studentsubjectgrade
               ON tbl_subject.SubjectID=studentsubjectgrade.SubjectID
               INNER JOIN academicyr ON studentsubjectgrade.SubjectID=academicyr.SubjectID
               WHERE academicyr.Semester = 1";
    $result = mysql_query($sql);
    $num    = mysql_numrows($result);

    mysql_close();

?>
    <table border='1'>
    <tr>
    <td>Subject ID</td>
    <td>Subject</td>
    <td>Finals</td>
    </tr>

<?php
    for ($i = 0; $i < $num; $i++)
    {

    $SID    = mysql_result($result,$i,"SubjectID");
    $SubjectDesc    = mysql_result($result,$i,"SubjectDesc");
    $Finals = mysql_result($result,$i,"Finals");

?>  
    <tr>
        <td><?php echo $SID; ?></td>   
        <td><?php echo $SubjectDesc; ?></td>   
        <td><?php echo $Finals; ?></td>    

    </tr>
<?php
    }
?>

The problem is when I login student2, the grades of student1 will still appear..

When you run this SQL query outside of your PHP code do you get more than one row?

SELECT tbl_subject.SubjectID, tbl_subject.SubjectDesc, studentsubjectgrade.Finals
               FROM tbl_subject 
               INNER JOIN studentsubjectgrade
               ON tbl_subject.SubjectID=studentsubjectgrade.SubjectID
               INNER JOIN academicyr ON studentsubjectgrade.SubjectID=academicyr.SubjectID
               WHERE academicyr.Semester = 1

yes sir..

I don't see any query sorting the grades based on the studentID or student subject grade based on the studentID. It has to be the unique, and not the subject. Otherwise, your database will just output anything that is true eventhough it does not belong to particular studentID.

YOu will need to show how is your database table constructed.

Sir, I added the studentID.. This is my new SQL statement.

SELECT tbl_subject.SubjectID, tbl_subject.SubjectDesc, studentsubjectgrade.Finals, studentsubjectgrade.StudentID
               FROM tbl_subject 
               INNER JOIN studentsubjectgrade
               ON tbl_subject.SubjectID=studentsubjectgrade.SubjectID
               INNER JOIN academicyr ON studentsubjectgrade.SubjectID=academicyr.SubjectID
               WHERE academicyr.Semester = 1

Where will I compare the StudentID? and what will I use? POST or GET?

Member Avatar for LastMitch

@janskey15

Where will I compare the StudentID? and what will I use? POST or GET?

Like what veedeoo mention show your table.

For example used this:

<?
$showtablequery = "SHOW TABLES FROM [database]";

$showtablequery_result  = mysql_query($showtablequery);
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
echo $showtablerow[0]."<br />";
}
?>

After you run that code post the table. All you need to do is copy and paste the table on to the Daniweb TextEditor. So we can see your table.

@LastMitch

Eng 11
Fil 1
Econ 1
Math 1
Psych 1
CS 101
RS 1
PE 1
NSTP 1 CWTS
These are the results of that code..

Member Avatar for LastMitch

@janskey15

These are the results of that code..

I think I gave you the wrong code. Sorry about that! It's still useful. It show the courses. But we need the see the table regarding about the studentID.

For example your db table should look like this:

id int(11) NOT NULL auto_increment,
username varchar(24) NOT NULL,
password varchar(24) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY username (username)

When you post your table it should look like this:

id | username | password |

This is what veedeoo mention about show your table.

Sorry about the confusion.

@LastMitch

GradeID SubjectID SubjectOfferingID ReservationID StudentID Finals Prelim Midterm Prefinals Remarks

these are my tables sir..

Here is my suggestion. Please examine how the tables are constructed and their relationships. They are related on two things course section and studentID.

table for the members , can accept students or proffessors

table name: members
columns:
id = auto-incremented
username
password
type = student->001, professors->007
studentID = unique for student ONLy.
year = school year
terms = semesters .e.g. fall, spring, winter, summer etc.
status = true or false .. this to filter if the student is enrolled or not
courses= This is should be the integer of number of courses the student is enrolled on current term. You must increment this by the number of courses, when the student confirmed enrollment.

Table name: courses
columns:
c_id = auto incremented
c_name = course name
c_desc = course description
c_section = course section
c_term = course semester offerings
c_max = maximum number of students this course allows to be enrolled at any given time

Table name: current_enrollement
columns:
e_id = NOT auto-incremented must be equal to the c_id in the courses table
e_section = course section where students are enrolled
e_studentID = student id of the student enrolled in this class
e_coursetitle = title of the course equal to the c_name in the courses table

Table name: grades
columns:
g_id = auto incremented
g_courseId = equal to the c_section in the courses table
g_studentId = equal to the student_ID in members table
g_term = semester term equivalent to the member's terms and courses terms
g_year = the year this grade has been issued or the semester's year.
g_prelim = grades for preminary exams
g_medterm = grades for mid-term exams
g_final = grades for final exams
g_gpa = grade point average for

You can add more tables as required.

Example query for my suggested table. **WARNING! This is just an example and NOT tested ,NOR have I given them a second thoughts.
**
Select students that are active

$query = "SELECT username, studentID, status FROM members WHERE status = 'true'";

Select the courses where the student is currently enrolled

$query = "SELECT type, studentID, e_studentID, e_section, c_name, c_description FROM members LEFT JOIN 'current_enrollment' ON('members.studentID'= 'current_erollment.e_studentID') LEFT JOIN 'courses' ON( 'enrollment.e_section' = 'course.c_section') WHERE status = 'true' AND studentID='studentID' ";

Select grades for a given studentID

$query = "SELECT * FROM grades WHERE studentID = 'studentID'";
commented: Very Detailed Explanation! +9
Member Avatar for LastMitch

@janskey15

The problem is when I login student2, the grades of student1 will still appear..

Maybe you can explain it more in detail about issue.

This is table you provided:

GradeID | SubjectID | SubjectOfferingID | ReservationID | StudentID | Finals | Prelim | Midterm | Prefinals | Remarks

I am confused when you mention that you enter the student2 grade and instead of student2 grade appearing it's student1 grade appear?

Am I correct?

This your query:

$sql = "SELECT tbl_subject.SubjectID, tbl_subject.SubjectDesc,studentsubjectgrade.Finals
FROM tbl_subject
INNER JOIN studentsubjectgrade ON tbl_subject.SubjectID=studentsubjectgrade.SubjectID
INNER JOIN academicyr ON studentsubjectgrade.SubjectID=academicyr.SubjectID
WHERE academicyr.Semester = 1";

I don't see that issue appearing from query above.

I think you are missing another query that SELECT a StudentID from DB.

The code that veedeoo provided has another query that prevent mismatch of grades between students which is this query:

$query = "SELECT * FROM grades WHERE studentID = 'studentID'";

You query should look like this:

$query = "SELECT * FROM GradeID WHERE StudentID = 'StudentID'";

I hope you understand what veedeoo mention in his previous thread.

@LastMitch
yes you are correct.
What I am trying to find out is how to compare the StudentID to the password(StudentID) given by student2. This is my SQL statement but the there is ana error.

"SELECT tbl_subject.SubjectID, tbl_subject.SubjectDesc, studentsubjectgrade.Finals, studentsubjectgrade.StudentID
               FROM tbl_subject
               INNER JOIN studentsubjectgrade
               ON tbl_subject.SubjectID=studentsubjectgrade.SubjectID
               INNER JOIN academicyr ON studentsubjectgrade.SubjectID=academicyr.SubjectID
               WHERE academicyr.Semester = 1
               AND studentsubjectgrade.StudentID='".$_GET['valid_id']."'";
Member Avatar for LastMitch

@janskey15

What I am trying to find out is how to compare the StudentID to the password(StudentID) given by student2. This is my SQL statement but the there is ana error.

I think you confused me I thought you mention that you enter the student2 grade and instead of student2 grade appearing it's student1 grade appear.

So what you want is compare StudentID to the password(StudentID)?

Just follow veedeoo example:

   $query = "SELECT type, studentID, e_studentID, e_section, c_name, c_description 
   FROM members 
   LEFT JOIN 'current_enrollment' 
   ON('members.studentID'= 'current_erollment.e_studentID') 
   LEFT JOIN 'courses' 
   ON( 'enrollment.e_section' = 'course.c_section') 
   WHERE status = 'true' 
   AND studentID='studentID' ";

Look closely what table structure he has and compare to your table structure. Follow exactly the same way.

You need to change you query a little to match up with his query.

So far this is your tbl_subject table:

GradeID | SubjectID | SubjectOfferingID | ReservationID | StudentID | Finals | Prelim | Midterm | Prefinals | Remarks

If tbl_subject is your table above then what is in studentsubjectgrade table?

I think I realized you have 2 different tables with 2 different set of data in it.

Kinda like what veedeoo has.

This is your query:

"SELECT tbl_subject.SubjectID, tbl_subject.SubjectDesc, studentsubjectgrade.Finals, studentsubjectgrade.StudentID
FROM tbl_subject
INNER JOIN studentsubjectgrade
ON tbl_subject.SubjectID=studentsubjectgrade.SubjectID
INNER JOIN academicyr 
ON studentsubjectgrade.SubjectID=academicyr.SubjectID
WHERE academicyr.Semester = 1
AND studentsubjectgrade.StudentID='".$_GET['valid_id']."'";

I don't know the other table data so you really need to follow the example that veedeoo provided.

He gave you the whole answer.

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.