I need a bit of help separating id’s that are separated by a comma and then displaying them in a dropdown list.
Here’s the code below that i am working with, if the clothing_type_id has only 1 number in it, it works fine, if i add more numbers so it’s split by a comma i.e 1,2,3,4 it will no longer work, i’m sure i need to use explode but i can not get it to work. Any help will be appreciated.
<? $clothing=intval($_GET['clothing_var']);
include 'classes.php';
mysql_select_db('database');
$query="SELECT ID,Qty_Values FROM Quantity WHERE Clothing_Type_ID='$clothing'";
$result=mysql_query($query);
$test=explode(',', '$result');
?>
<select name="state" onchange="getCity(<?=$clothing?>,this.value)">
<option>Select State</option>
<? while($row=mysql_fetch_array($test)) { ?>
<option value=<?=$row['ID']?>><?=$row['Qty_Values']?></option>
<? } ?>
</select>
UPDATE:
Here’s what i’m trying todo.
Hi, pasted your code in and although it works, it only brings up the first selection, if i click on the 2nd id nothing displays. My database table goes like this, the fist selection called Clothing_Type has 3 columns, ID Garment and Price, the second table has 4 columns, ID, Clothing_Type_ID, Qty_Values and price. Basically I am trying to do is make a pricing guide so if i select a t-shirt in the first selection box it will bring up 4 prices at the end of the form, 1 for each item, 2 for a total amount (If selecting a higher quantity) 3 for VAT and 4 Total Amount. Every time selection is selected then it will automatically update the price. After i’ve selected 3 or 4 selection boxes, i then want a few checkboxes again to update the price if they’re ticked.
Update 2: Here’s the js and html
JS
<script language="javascript" type="text/javascript">
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getQty(countryId) {
var strURL="findQty.php?clothing_var="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('qtydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCity(countryId,stateId) {
var strURL="findCity.php?clothing_var="+countryId+"&qty_var="+stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
HTML
<body>
<form method="post" action="" name="form1">
<?
include 'classes.php';
$query="SELECT ID,Garment FROM Clothing_Type";
$result=mysql_query($query);
?>
<select name="clothing_type" onChange="getQty(this.value)">
<option>Select Clothing Type</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['ID']?>><?=$row['Garment']?></option>
<? } ?>
</select>
<p id="qtydiv">
<select style="width: 150px;" name="qty" disabled='disabled'>
<option>Select Country First</option>
</select>
</p>
<p id="citydiv">
<select style="width: 150px;" name="city" disabled='disabled'>
<option>Select State First</option>
</select>
</p>
<input type="checkbox" name="vehicle" value="Bike" /> I want to live here<br />
<form>
<input type='checkbox' name='1' value='1'id='checkbox_1' />1<br>
<input type='checkbox' name='2' value='2'id='checkbox_2' />2<br>
<input type='checkbox' name='3' value='3'id='checkbox_3' />3<br>
</form>
</body>
Try this,
$clothing = “1,2,3,4”;
$query=”SELECT ID,Qty_Values FROM Quantity WHERE Clothing_Type_ID IN ($clothing)”;