Skip to content

Instantly share code, notes, and snippets.

@Lasha
Created April 19, 2010 04:17
Show Gist options
  • Save Lasha/370747 to your computer and use it in GitHub Desktop.
Save Lasha/370747 to your computer and use it in GitHub Desktop.
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$con = mysql_connect("localhost","student","password1236");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("final_studentgrades", $con);
?>
<input type="text" id="sortBy" name="sortBy" />
<input type="text" id="abc" name="abc" />
<input type="text" id="searchFor" name="searchFor" />
<script>
function sortBy(pSortBy)
{
alert("testing sort" + pSortBy);
var sortOrder = document.getElementById("abc");
var whichpage = document.getElementById("whichpage");
whichpage.value = 4;
sortOrder.value = pSortBy;
document.forms[0].submit();
}
function likeClause(pSearchBy)
{
var searchFor = document.getElementById("searchFor");
var whichpage = document.getElementById("whichpage");
whichpage.value = '4';
searchFor.value = pSearchBy;
alert("testing my filter: " + pSearchBy);
alert("which page: " + whichpage.value)
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>
<hr />
<a href="javascript:likeClause('A')"> A </a>
<a href="javascript:likeClause('B')"> B </a>
<a href="javascript:likeClause('C')"> C </a>
<a href="javascript:likeClause('D')"> D </a>
<hr />
<?php
$sql = "SELECT lastname\n"
. "FROM `NYStudents`\n"
. "WHERE lastname like \n";
$ascValue = "";
echo $ascValue;
for ($ascValue = 65; $ascValue <= 90; $ascValue++) {
$letter = chr($ascValue);
echo " <a href=";
echo '"javascript:likeClause(';
echo "'$letter'";
echo ')">' . $letter . '';
$letteRr = "'$letter%'";
$result = mysql_query($sql . $letteRr);
$rowCount = mysql_num_rows($result);
echo "(" . $rowCount . ")";
echo '</a>';
}
?>
<hr />
</span>
<br />
<ul>
<table border="0" cellspacing="0" class="nytReport">
<tr>
<th>student id</th>
<th>first name</th>
<th>last name</th>
</tr>
<?php
/*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";
$likeClause = "";
if(isset($_GET["searchFor"]))
{
$likeClause = $_GET["searchFor"];
}
$sql = "SELECT studentId, firstname, lastname\n"
. "FROM `NYStudents`\n"
. "WHERE lastname like '$likeClause%'\n";
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);
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];
echo "<tr><td>$theId</td>
<td>$theFName</td>
<td>$theLName</td></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