1,105,625 Community Members

select partner display customer in ajax

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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.
Member Avatar
AleMonteiro
Master Poster
758 posts since Aug 2010
Reputation Points: 115 [?]
Q&As Helped to Solve: 143 [?]
Skill Endorsements: 29 [?]
 
0
 

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

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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">
Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

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

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

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>
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: