twilitegxa Posted January 30, 2010 Share Posted January 30, 2010 I have the following script: <?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("smrpg", $con); $sql="SELECT * FROM monsters1 WHERE id = '".$q."'"; $result = mysql_query($sql); echo "<table border='0'>"; while($row = mysql_fetch_array($result)) { echo "Select a location: <select>"; echo "<option>" . $row['location'] . "</option>"; } echo "</select>"; mysql_close($con); ?> This code starts with an HTML page that uses a js and the above php script to fill the div area: HTML: <?php $get_map = "select * from monsters1 group by map"; $get_map_res = mysql_query($get_map, $conn) or die(mysql_error()); echo "<select name=\"maps\" onchange=\"showMap(this.value)\"> <option selected=\"selected\">None Selected</option>"; while ($list_maps = mysql_fetch_array($get_map_res)) { $map_id = $list_maps['id']; $map = $list_maps['map']; echo "<option value=\"$map_id\">$map</option>"; } echo "</select>"; ?> <div id="txtHint2"></div> js script: var xmlhttp2; function showMap(str) { xmlhttp2=GetXmlHttpObject(); if (xmlhttp2==null) { alert ("Browser does not support HTTP Request"); return; } var url2="getlocations.php"; url2=url2+"?q="+str; url2=url2+"&sid="+Math.random(); xmlhttp2.onreadystatechange=stateChanged2; xmlhttp2.open("GET",url2,true); xmlhttp2.send(null); } function stateChanged2() { if (xmlhttp2.readyState==4) { document.getElementById("txtHint2").innerHTML=xmlhttp2.responseText; } } function GetXmlHttpObject2() { if (window.XMLHttpRequest2) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest2(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } But right now, $q is the id, so whenever the user selects an option from the first select list, the second select list only populates with one record. What I want it to do is populate with all unique values according to the map field, because there are multiple records that have the same value in map, so I want all field with the same value in map to show those records in the location field. Location also has many fields with the same value, so I want this select list to populate with all unique values. Can anyone help? What am I doing wrong? I don't know how to set the where statement to display the values from location based on the map field and not the id field. Can anyone help? Link to comment https://forums.phpfreaks.com/topic/190388-where-statement-help/ Share on other sites More sharing options...
twilitegxa Posted January 31, 2010 Author Share Posted January 31, 2010 I moved this to the JS section and it is solved. Link to comment https://forums.phpfreaks.com/topic/190388-where-statement-help/#findComment-1004508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.