need to dispaly search results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
misticles
Forum Newbie
Posts: 1
Joined: Tue Apr 14, 2009 9:35 am

need to dispaly search results

Post by misticles »

I found this code on the internet and managed to adapt it to suit my program. the problem is I cant get it display the search results and need help with this
I am using 3 drop down menus that are dynamically populated. below are the tables that I am using and the code.

any help is greatly appreciated as I have been trying to do this for 2 weeks now.
elements

course_code course_year subject sitting year link
DT205 2 Calculus/Analysis Semester 2 2006/2007 Click here
DT205 3 Classical Mechanics Semester 1 2006/2007 Click here
DT205 3 Classical Mechanics Semester 1 2007/2008 Click here
DT205 4 Integral Equations Semester 2 2006/2007 Click here



coursecodetable

courseid course_code
1 dt205
2 dt008

courseyeartable

yearid courseid course_year
1 1 1
2 1 2
3 1 3
4 1 4
5 2 1
6 2 2
7 2 3

Code: Select all

 
<?php
 
$programme = $progyear = $subjectname = $examyear = null; //declare vars
 
$conn= mysql_connect("localhost", "root", "7mysql12user");
$db = mysql_select_db('exampapers',$conn);
 
if(isset($_GET["programme"]) && is_numeric($_GET["programme"]))
{
$programme = $_GET["programme"];
}
 
if(isset($_GET["progyear"]) && is_numeric($_GET["progyear"]))
{
$progyear = $_GET["progyear"];
}
 
if(isset($_GET["subjectname"]) && is_numeric($_GET["subjectname"]))
{
$subjectname = $_GET["subjectname"];
}
 
if(isset($_GET["examyear"]) && is_numeric($_GET["examyear"]))
{
$examyear = $_GET["examyear"];
}
 
?>
 
<script language="JavaScript">
 
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
 
</script>
 
<form name="theForm" method="get">
 
 
 
<select name="programme" onChange="autoSubmit();">
<option value="null"></option>
<option value="1" <?php if($programme == 1) echo " selected"; ?>>DT205</option>
<option value="2" <?php if($programme == 2) echo " selected"; ?>>DT008</option>
</select>
 
<br><br>
 
 
 
<?php
 
if($programme != null && is_numeric($programme))
{
 
?>
 
<select name="progyear" onChange="autoSubmit();">
<option value="null"></option>
 
<?php
 
//POPULATE DROP DOWN MENU WITH course_year FROM A GIVEN course_code
 
$sql = "SELECT DISTINCT yearid, course_year FROM courseyeartable WHERE courseid = $programme";
$progyears = mysql_query($sql, $conn);
 
while($row = mysql_fetch_array($progyears))
{
echo ("<option value=\"$row[yearid]\" " . ($progyear == $row["yearid"] ? " selected" : "") . ">$row[course_year]</option>");
}
 
?>
 
</select>
 
<?php
 
}
 
?>
 
<br><br>
 
<?php
 
if($progyear != null && is_numeric($progyear) && $programme != null)
{
 
?>
 
<select name="subjectname" onChange="autoSubmit();">
<option value="null"></option>
 
<?php
 
//POPULATE DROP DOWN MENU WITH subjects FROM A GIVEN course_code, course_year
 
$sql = "SELECT DISTINCT subject from elements WHERE course_year = $progyear ";
$subjects = mysql_query($sql,$conn);
 
while($row = mysql_fetch_array($subjects))
{
echo ("<option value=\"$row[subject]\" " . ($subjects == $row["subject"] ? " selected" : "") . ">$row[subject]</option>");
}
 
?>
 
</select>
 
<?php
 
}
 
?>
 
 
</form>
 
 
 
Post Reply