.

.
how to call ajax event with in php loop & pass two variable in ajax url

how to call ajax event with in php loop & pass two variable in ajax url

PHP LO0P 
Call Event with in loop and change Id according to id
Take an custom Id where we want to display ajax result

<?php foreach($basketproduct as $basket)
{?>
<tr><td><img src="productimages/<?php echo $basket['productimage'] ;?>" width="150" height="200" ></td>
<td><?php echo $basket['description'] ;?></td>
<td><?php echo $basket['sellingprice'] ;?></td>
<td>
<!--<input type="hidden" id="mainbid" value="<?php echo $basket['id'];?>" >-->
<select name="quantity" onchange="changetotal(this.value,<?php echo $basket['id'];?>)">
<?php for($i=1;$i<=30;$i++)
{?>
<option value="<?php echo $i;?>" <?php if($basket['quantity']==$i){ echo 'selected="selected"'; }?>><?php echo $i;?></option>
<?php }?>
</select>


</td>

<td><span id="total<?php echo $basket['id'];?>"> <?php echo $basket['subtotal'] ;?></span></td>

</tr>
<?php } ?>

Call ajax 

<script type="text/javascript">
function changetotal(str,mainid)
{

//var mainid=document.getElementById("mainbid").value;
var url= 'ajaxbasketprice.php?id='+mainid+'&qty='+str;
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("total"+mainid).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET",url,true);
xmlhttp.send();
}


</script>

ajaxbasketprice.php


<?php 
include 'init.php';
connection2();

$mainid=$_GET['id'];
 $qty = $_GET['qty'];
//$up=$bas->updatebasket($qty,$mainid);
$sql=mysql_query("update great_basket set `quantity`='".$qty."', subtotal= ".$qty." * sellingprice  where id='".$mainid."'");
$sql1 =mysql_query("SELECT * FROM great_basket WHERE id = '".$mainid."' ");
while($res=mysql_fetch_assoc($sql1))
{
echo $res['subtotal'];

}


?>