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.

What's the problem with your code? What's not working? Which erros does it throw? What can't you figure out?

Hi,
The problem is already mentioned . Using dropdown I was able to show and excute but I want to display in a table not in dropdown.I am not able to display in table like

 <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="of border" id="customerdiv">

place this logic in findCusomer.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
               //  retrive your data here
               ?>
            <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
                 // close the database connection here 
               ?>

check it once

can you check is there any problem at line no: 30 in your html with php page?

i mean here

<td>
<a name="country" id="country" href="<?php $_SERVER['PHP_SELF']?>?ans=<?php echo $respartnerlist['dealercode'];?>" onclick="getPartner(this.value)">Customer list</a>
</td>

I checked it out with

    <td>
    <a name="country" id="country" href="<?php $_SERVER['PHP_SELF']?>?ans=<?php echo $respartnerlist['dealercode'];?>" onclick="getPartner(this.value)">Customer list</a>
    </td>

but the problem is ajax is not called onclick="getPartner(this.value)" and that is the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.