misticles Posted April 10, 2009 Share Posted April 10, 2009 Hi, I will explain this the best I can, I want to display the data as follows, I search dt205 year 2 calculus/analysis in our drop downs I want it to display results: dt205 year 2 calculus/analysis semester 2 2006/2007 and Link. So far I cant get it to display anything like above, tried a few ways but no joy. below are the tables I am using and the code which propmts the user to pick a course code, year and subject using dropdowns. dropdowns are dependant eachother. ie selection of course year depends on course code picked etc The database is exampapers, the tables are: 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 DT205 4 Differential Equations Semester 1 2006/2007 Click here DT205 4 Differential Equations Semester 1 2007/2008 Click here DT205 1 Computer Architecture Semester 1 2008/2009 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 The code is: <?php $programme = $progyear = $subjectname = $examyear = null; //declare vars $conn= mysql_connect("localhost", "root", "pwrd"); $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> Link to comment https://forums.phpfreaks.com/topic/153464-cannot-get-this-to-display-any-results-from-search/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.