hi all ,
I want to display partner list from database which is done.Now I want to display it's customers list by clicking on each parter using ajax. here is ajax code :
<script language="javascript" type="text/javascript">
function getXMLHTTP()
{ //fuction to return the xml http object
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 getPartner(partnerId) {
var strURL="findCustomer.php?partner="+partnerId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('customerdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
here is html with php:
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="of border">
<?php
error_reporting(E_ALL ^ E_NOTICE);
$country=intval($_GET['country']);
$sqlpartnerlist="select * from dealer_dummy where dealercode='$dealercode' ;
$qrypartnerlist=mysql_query($sqlpartnerlist);
?>
<tr>
<td>List of partners</td>
</tr>
<?php
while($respartnerlist=mysql_fetch_array($qrypartnerlist))
{
?>
<tr>
<td><?php echo $respartnerlist['dealercode'];?></td>
<td> </td>
<td><?php echo $respartnerlist['country'];?></td>
<td> </td>
<td><?php echo $respartnerlist['dealer'];?></td>
<td> </td>
<td><?php echo $respartnerlist['discount'];?></td>
<td> </td>
<td><?php echo $respartnerlist['currency'];?></td>
<td> </td>
<td><a name="country" id="country" href="<?php $_SERVER['PHP_SELF']?>?ans=<?php echo $respartnerlist['dealercode'];?>" onclick="getPartner(this.value)">Customer list</a></td>
<td> </td>
</tr>
<?php
}
?>
</table>
here is to display customer list on clicking partner :
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="of border" id="customerdiv">
<?php
?>
<tr>
<td>List of customers of each partner from partner list</td>
</tr>
<tr>
<td>Dealer Code</td>
<td> </td>
<td>Country</td>
<td> </td>
<td>Dealer</td>
<td> </td>
<td>Discount (%)</td>
<td> </td>
<td>Currency</td>
<td> </td>
<td>Customer list</td>
<td> </td>
</tr>
<tr>
<td>-------------</td>
<td> </td>
<td>-------------</td>
<td> </td>
<td>-------------</td>
<td> </td>
<td>-------------</td>
<td> </td>
<td>-------------</td>
<td> </td>
<td>------------------</td>
<td> </td>
</tr>
<?php
?>
<tr>
<td><?php echo $result['customer_number'];?></td>
<td> </td>
<td><?php echo $result['customer_name'];?></td>
<td> </td>
<td><?php echo $result['currency_code'];?></td>
<td> </td>
<td><?php echo $result['discount'];?></td>
<td> </td>
<td><?php echo $result['dealercode'];?></td>
<td> </td>
</tr>
<?php
?>
</table>
and here is findCustomer.php code
<?php
error_reporting(E_ALL ^ E_NOTICE);
$partner=$_GET['partner'];
$link = mysql_connect('localhost', 'root', ''); //change the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
$query="SELECT FROM customer_list WHERE dealercode='$partner'";
$result=mysql_query($query);
?>
This code is inspired by "on selection country ,respective state will be displayed using ajax in dropdown " but I want to display in table not drop down.
Thanks in advance.