Created
April 16, 2010 22:08
-
-
Save Lasha/369038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('error_reporting', E_ALL); | |
ini_set('display_errors', 1); | |
?> | |
<input type="hidden" id="sortBy" name="sortBy" /> | |
<input type="hidden" id="abc" name="abc" /> | |
<script> | |
function sortBy(pSortBy) | |
{ | |
alert("testing sort" + pSortBy); | |
var sortOrder = document.getElementById("abc"); | |
var whichpage = document.getElementById("whichpage"); | |
whichpage.value = 1; | |
sortOrder.value = pSortBy; | |
document.forms[0].submit(); | |
} | |
</script> | |
<h1 id="topic">Student Reports</h1> | |
<br /> | |
<span>SORT BY: | |
<a href="javascript:sortBy('asc');">Alphabetical: A-Z</a> | | |
<a href="javascript:sortBy('desc');">Alphabetical: Z-A</a> | | |
<a href="index.php?whichpage=1&sortBy=lastname">Last Name</a>| | |
<a href="index.php?whichpage=1&sortBy=firstname">First Name</a>| | |
<a href="index.php?whichpage=1&sortBy=studentId">Student ID</a> | |
</span> | |
<br /> | |
<ul> | |
<table border="0" cellspacing="0" class="nytReport"> | |
<tr> | |
<th>Student Id</th> | |
<th>First Name</th> | |
<th>Last Name</th> | |
<th>Student Grade</th> | |
<th>Scores</th> | |
</tr> | |
<?php | |
$con = mysql_connect("localhost","student","password1236"); | |
if (!$con) | |
{ | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db("final_studentgrades", $con); | |
/*below , you see the student Id has a space then xxx, it is an "alias" | |
Make sure now you can use the Alias when you echo studentId, change it to the | |
Alias xxx | |
$sql = "SELECT studentId xxx, firstname, lastname | |
FROM `nystudents` WHERE 1 LIMIT 0, 30 "; | |
$sql = "SELECT studentGradesId,StudentGradesLookUpId,studentId,studentGrade FROM `StudentGrades` WHERE studentId=100"; | |
$sql2 = "SELECT A1.studentId,A1.firstname,A1.lastname,A2.studentGrade FROM NYStudents A1,StudentGrades A2\n" | |
. "WHERE A1.studentId = A2.studentId"; | |
//This query outputs each user ID 5 times - for every test score. | |
$sql = "select n.studentid, firstname, lastname, studentgrade\n" | |
. "from nystudents n\n" | |
. "inner join studentgrades sg\n" | |
. "on n.studentid = sg.studentid"; */ | |
//This qyuery outputs the ID once, and shows the student average grade. "Scores" should show the user's 5 scores. | |
$sql = "SELECT A1.studentId, A1.firstname, A1.lastname, AVG(A2.studentGrade), A2.studentGrade\n" | |
. "FROM NYStudents A1, StudentGrades A2\n" | |
. "WHERE A1.studentId = A2.studentId\n" | |
. "GROUP BY A1.studentId"; | |
if ( isset($_GET["sortBy"]) ) | |
$sortBy = $_GET["sortBy"]; | |
else | |
$sortBy = "studentId"; | |
if ( isset($_GET["abc"]) ) | |
$az = $_GET["abc"]; | |
else | |
$az = "asc"; | |
$orderby = " order by $sortBy $az"; | |
echo $sql . $orderby; | |
$result = mysql_query($sql . $orderby); | |
// $result2 = mysql_query($sql2); | |
while($row = mysql_fetch_array($result)) | |
{ | |
//echo $row['studentId'] . " " . $row['firstname']. " " . $row['lastname']; | |
//print_r($row); | |
//echo "<hr />"; | |
$theId = $row[0]; | |
$theFName = $row[1]; | |
$theLName = $row[2]; | |
$theGrade = $row[3]; | |
echo "<tr><td>$theId</td>"; | |
echo "<td>$theFName</td>"; | |
echo "<td>$theLName</td>"; | |
echo "<td>$theGrade</td>"; | |
echo "<td>student grade is an average of 5 grades. they must be listed here.</td>"; | |
echo "</tr>"; | |
} | |
mysql_close($con); | |
?> | |
</table> | |
</ul> | |
<script> | |
var data = document.getElementById("sortBy") | |
data.value = "<?php echo $sortBy; ?>"; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment