misticles Posted April 12, 2009 Share Posted April 12, 2009 Im fairly new to php and mysql. Im creating a database, to search them there is 3 dynamically populated drop down menus. when I press the submit button after selecting the data, nothing comes up. Im using 3 different tables to pull information from. this is the code I have The code is: <?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> Link to comment https://forums.phpfreaks.com/topic/153697-cannot-display-results-from-a-search/ Share on other sites More sharing options...
revraz Posted April 12, 2009 Share Posted April 12, 2009 Echo your queries to see if they contain what you expect them to. Link to comment https://forums.phpfreaks.com/topic/153697-cannot-display-results-from-a-search/#findComment-807723 Share on other sites More sharing options...
misticles Posted April 12, 2009 Author Share Posted April 12, 2009 how do ya mean? i have echo statements but theyre not doing as they should Link to comment https://forums.phpfreaks.com/topic/153697-cannot-display-results-from-a-search/#findComment-807850 Share on other sites More sharing options...
Anxious Posted April 12, 2009 Share Posted April 12, 2009 Put your codes in Code tags [ code ] [/ code ] without the spaces, so that it's easter to read. As what revraz is saying, there is an error, being as it doesn't display results. Is it even knowing what results to get from the database? You'll need to put echo's in somewhere, and keep testing it. If you can get a results page, with the echo you put in, then you know that bit works. Usually, you'd put an echo after an If statement. Instead of displaying the whole page of results, try one part, eg: for a news article as a result, you'd just test out the title first. I'm not sure what to do, revraz would know better. You say you have echo statements but not doing as they should, remove a statement and put a normal statement eg: <?php echo("No error here"); ?> If that displays, then you know theres no error up to that point, so you remove that echo, and put it further down the process, until you get to the point where it doesn't display, that way you know where the error would most probably be. Link to comment https://forums.phpfreaks.com/topic/153697-cannot-display-results-from-a-search/#findComment-807878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.