Jump to content

pbrandy22

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Everything posted by pbrandy22

  1. Hi everyone, I've read through the FAQs for Dynamic Dropdown Menus on this site, as well as others, and I can't figure out why my code won't work. I have two dropdown boxes that need to be populated with data from a mysql table; one menu for route types, and one for route numbers. When I choose the route from the 'Route' menu, the 'Number' menu automatically populates with all of the possible numbers, rather than only those that correspond with the route type. I can tell that the problem has something to do with the value of 'Route' not being recognized, but I don't know why. I'm a beginner when it comes to PHP, so any suggestions or help would be much appreciated! Thanks! The code is as follows: <html> <body> <basefont face='calibri' color='#7E2217'> <?php // set variables $mileTable = $_GET['mileTable']; $routeType = isset($_POST['Roadtype'])? $_POST['Roadtype']: 0; include 'opendbMile.php'; include 'error.php'; // Connect to the MySQL DBMS if (!($connection = @ mysql_connect($hostName, $username, $password))) die("Could not connect"); if (!mysql_select_db($databaseName, $connection)) showerror( ); // Start a query... $query = "SELECT ID, Roadtype FROM Alabama GROUP BY Roadtype"; // execute the SQL statement $result = mysql_query($query, $connection) or die(mysql_error()); echo '<form name="mileform" method="post" action="MileQuery.php">'; echo '<p>Route: <select name="routeType" id="routeType" onchange="this.form.submit();"> <option value="0"'.($routeType == 0? ' SELECTED': '').'>Route</option>'; while($row = mysql_fetch_array($result)){ echo ' <option value="'.$row[0].'"'.(($routeType == $row[0])? ' SELECTED': '').'>'.$row[1].'</option>'; } echo ' </select> </p>'; // create the SQL statement $query2 = "SELECT ID, Roadnumber FROM Alabama GROUP BY Roadnumber"; if($mnucategory != 0){ // Filter road numbers $query2 .= " WHERE Roadtype='".$routeType."'"; } // execute the SQL statement $result2 = mysql_query($query2, $connection) or die(mysql_error()); echo '<p>Number: <select name="routeNumber" id="routeNumber" onchange="this.form.submit();"> <option value="0"'.($routeNumber == 0? ' SELECTED': '').'>Number</option>'; while($row2 = mysql_fetch_array($result2)){ echo ' <option value="', $row2[0].'"'.(($routeNumber == $row2[0])? ' SELECTED': '').'>'. $row2[1], '</option>'; } echo ' </select> </p>'; // Close the DBMS connection mysql_close($connection); ?> </form> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.