sandsquid Posted November 10, 2007 Share Posted November 10, 2007 I have a script that my users will select first line of choices a,b, and c from a dropdown lists. I also have it so that they can add a new line of choices d,e and f from 3 new dropdown lists. However, a,b and c works perfectly with my data populated. However d,e and f will not populate with my data from my db. <?php $dbservertype='mysql'; $servername='mysqlhost'; $dbusername='name'; $dbpassword='password'; // name of database $dbname='mydb'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Where you served - MyDutyStation.com</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.service.options[form.service.options.selectedIndex].value; self.location='served.php?service=' + val ; } function reload3(form) { var val=form.service.options[form.service.options.selectedIndex].value; var val2=form.country.options[form.country.options.selectedIndex].value; var val3=form.command_name.options[form.command_name.options.selectedIndex].value; self.location='served.php?service=' + val + '&country=' + val2 + '&command_name=' + val3; } // Last updated 2006-02-21 function addRowToTable() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById("theValue").value -1)+ 2; numi.value = num; var divIdName = "my"+num+"Div"; var newdiv = document.createElement('div'); newdiv.setAttribute("id",divIdName); newdiv.innerHTML = "Some text here"; ni.appendChild(newdiv); var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; var row = tbl.insertRow(lastRow); //Title var cellLeft = row.insertCell(0); var textNode = document.createTextNode('Service '+iteration+':'); cellLeft.appendChild(textNode); //Service var serviceCell = row.insertCell(1); serviceCell.appendChild(tbl.rows[1].cells[1].cloneNode(true)); //Country var countryCell = row.insertCell(2); countryCell.appendChild(tbl.rows[1].cells[2].cloneNode(true)); //Command var commandCell = row.insertCell(3); commandCell.appendChild(tbl.rows[1].cells[3].cloneNode(true)); } function removeRowFromTable() { var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length; if (lastRow > 2) tbl.deleteRow(lastRow - 1); } </script> </head> <body> <table border=1 id=tblSample> <tr> <td> </td><td>Service</td><td>Country</td><td>Command</td> </tr> <tr> <td>Service 1:</td> <? ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT service FROM militarydb"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// $cat=$HTTP_GET_VARS['service']; // This line is added to take care if your global variable is off if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT country FROM militarydb WHERE service = '$service'"); }else{$quer=mysql_query("SELECT DISTINCT country FROM militarydb WHERE service = '$service'"); } ////////// end of query for second country drop down list box /////////////////////////// /////// for Third drop down list we will check if sub category is selected else we will display all the country///// $cat3=$HTTP_GET_VARS['country']; // This line is added to take care if your global variable is off if(isset($ca3) and strlen($cat3) > 0){ $quer3=mysql_query("SELECT DISTINCT command_name FROM militarydb WHERE service = '$service' AND country = '$country' ORDER BY comman d_name"); }else{$quer3=mysql_query("SELECT DISTINCT command_name,major_units FROM militarydb WHERE service = '$service' AND country = '$countr y' ORDER BY command_name"); } ////////// end of query for third subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='served.php'>"; ////////// Starting of first drop downlist ///////// echo "<td><select name='service' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['service']==@$cat){echo "<option selected value='$noticia2[service]'>$noticia2[service]</option>"."<BR>";} else{echo "<option value='$noticia2[service]'>$noticia2[service]</option>";} } echo "</select></td>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// if($service != "None"){ echo "<td><select name='country' onchange=\"reload3(this.form)\"><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { if($noticia['country']==@$cat3){echo "<option selected value='$noticia[country]'>$noticia[country]</option>"."<BR>";} else{echo "<option value='$noticia[country]'>$noticia[country] </option>";} } echo "</select></td>"; }else{ echo "<p>Your all done! Thanks"; exit; } ////////////////// This will end the second drop down list /////////// ////////// Starting of third drop downlist ///////// echo "<td><select name='command_name'><option value=''>Select one</option>"; while($noticia1 = mysql_fetch_array($quer3)) { if($noticia1['command_name']==@$cat4){echo "<option selected value='$noticia1[command_name]'>$noticia1[command_name]</option>"."<BR> ";} else{ echo "<option value='$noticia1[command_name] $noticia1[major_units]'>$noticia1[command_name] $noticia1[major_units]</option>"; } } echo "</select></td>"; ////////////////// This will end the third drop down list /////////// ?> </tr> </table> <input type="hidden" value="0" id="theValue" /> <div id="myDiv" style="border: 3px coral solid;"> </div> <input type="button" value="Add" onclick="addRowToTable();" /> <input type="button" value="Remove" onclick="removeRowFromTable();" /> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.