dfowler Posted April 7, 2008 Share Posted April 7, 2008 Hey guys, I'm trying to get some dynamic dropdowns to work, but keep getting this error. Can somebody take a look at the code and tell me what I am doing wrong. Thanks! deletec.php <?php include 'system.php'; //FIRST list box $query = "select * from categories"; $list1 = array(); $result=mysql_query($query); while (($row = mysql_fetch_assoc($result)) !== false) { $list1[] = $row; } ?> <script type="text/javascript"> var AdminResponse = ""; function parseResponse(){ var nText = AdminResponse.getElementsByTagName('optionText'); var nVal = AdminResponse.getElementsByTagName('optionVal'); document.forms[0]['group'].options.length = 1; for (i=0; i<nText.length; i++) { var nOption = document.createElement('option'); var isText = document.createTextNode(nText[i].firstChild.data); nOption.setAttribute('value',nVal[i].firstChild.data); nOption.appendChild(isText); document.forms[0]['group'].appendChild(nOption); } } function update(nVal){ var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); AdminRequest.onreadystatechange = function() { if (AdminRequest.readyState == 4) { if (AdminRequest.status == 200) { AdminResponse = AdminRequest.responseXML; parseResponse(); } else { alert('Error update.php File '+ AdminRequest.statusText); } } } var infoStr = "?choice="+nVal; AdminRequest.open("GET", "update.php"+infoStr, true); AdminRequest.send(null); } </script> <form method="post" enctype="multipart/form-data" name="myForm" target="_self" action="deletec2.php"> <br /> <table cellpadding="3" cellspacing="3" border="0"> <tr> <td> Category: <select name="list1" onchange="update(this.value)"> <option value="0">Select Category</option> <?php foreach($list1 as $l) { ?> <option value="<?php echo $l['id']; ?>"><?php echo $l['name']; ?></option> <?php } ?> </select> PDF: <select name="group"> <option value=""> Make a selection </option> </select> </td> </tr> <tr> <td> <input type="submit" name="Submit" value="Submit" class="menu-next" /> </td> </tr> </table> </form> update.php <?php include 'system.php'; $choice = $_GET['choice']; $xml = "<?xml version='1.0' ?><options>"; $query = "SELECT * FROM cat_pdfs WHERE cat_id = '$choice'"; $cats = array(); $result = @mysql_query($query); while (($row = mysql_fetch_assoc($result)) !== false) { $cats[] = $row; } pdfs = array(); foreach($cats as $c) { sql = "SELECT * FROM pdfs WHERE id='".$c['pdf_id']."'"; $result2 = @mysql_query($sql); while (($row2 = mysql_fetch_assoc($result2)) !== false) { $pdfs[] = $row2; } } $num = @mysql_num_rows($result); if ($result && $num > 0) { foreach($pdfs as $p) { $xml .= "<optionText>" . $p['name'] . "</optionText><optionVal>" . $p['id'] . "</optionVal>"; } } $xml .= "</options>"; @mysql_free_result($result); @mysql_close(); header("Content-Type: text/xml"); echo $xml; ?> Quote Link to comment Share on other sites More sharing options...
dfowler Posted April 7, 2008 Author Share Posted April 7, 2008 Got it to work, here is the code: <?php include 'system.php'; $choice = $_GET['choice']; $xml = "<?xml version='1.0' ?><options>"; $query = "SELECT * FROM cat_pdfs WHERE cat_id = '$choice'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if ($result && $num > 0) { while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $sql = "SELECT * FROM pdfs WHERE id='".$row['pdf_id']."'"; $result2 = @mysql_query($sql); $num2 = @mysql_num_rows($result2); if ($result2 && $num2 > 0) { while ($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)) { $xml .= "<optionText>" . $row2['name'] . "</optionText><optionVal>" . $row2['id'] . "</optionVal>"; } } } } $xml .= "</options>"; @mysql_free_result($result); @mysql_close(); header("Content-Type: text/xml"); echo $xml; ?> 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.