i AM USING php AND MYSQL on WordPress in order to fetch data from mysql database and display the result in a table and plot a pin on Google map based on lat and long. i am using 3 depended dropbox.

I have 2 problems

Problem 1 : when i try to fetch the result from the database the first variable hold several fields


select i.siteID , i.siteNAME , i.equipmentTYPE , c.latitude , c.longitude , c.height , o.ownerNAME , o.ownerCONTACT , x.companyNAME , y.subcontractorCOMPANY , y.subcontractorNAME , y.subcontractorCONTACT from site_info i LEFT JOIN owner_info o on i.ownerID = o.ownerID LEFT JOIN company_info x on i.companyID = x.companyID LEFT JOIN subcontractor_info y on i.subcontractorID = y.subcontractorID LEFT JOIN site_coordinates2 c on i.siteID=c.siteID where **i.siteNAME = '17, 3,Samir Choueiri ,gds,Beit Mery**' AND o.ownerNAME = '17' AND x.companyNAME = '3' 

Problem 2 : it display the id and not the name.

i know that the problem is in the ** $query_site_name query** but i don’t know how to fix it.


<form method ="post" action ="" name="submit_form">
        <table border="0" width="30%">
               <td>Site Name</td>
               <td>Owner Name</td>
               <td>Company Name</td>
               <td>Subcontractor Name</td>
               <td><select id="site_name"  name = "site_name">
                      <option value="">Select Site</option>

                     $query_site_name =$wpdb->get_results("select DISTINCT 
                       from site_info i
                       JOIN owner_info o
                       on i.ownerID = o.ownerID
                       JOIN company_info x
                       on i.companyID = x.companyID
                      foreach($query_site_name as $row)
                       echo "<option value = '".$row ->ownerID.", ".$row ->companyID.",".$row ->ownerNAME.",".$row ->companyNAME.",".$row ->siteNAME."'>".$row->siteNAME."</option>";

                      // echo "<option value='".$row->siteID."'>".$row->siteNAME."</option>";



<!--create  dropdown list owner names-->
                <td><select id="owner_name"  name ="owner_name">
                <option value="">Select Owner</option>

<!--create  dropdown list Company names-->
                <td><select id="Company_name"  name ="Company_name">
                <option value="">Select Company</option>

<!--create  dropdown list Subcontractor names-->
                <td><select id="Subcontractor_name"  name ="Subcontractor_name">
                global $Subcontractor_name;
                    $query_Subcontractor_name =$wpdb->get_results ("select DISTINCT subcontractorID, subcontractorNAME  from subcontractor_info");
                     foreach($query_Subcontractor_name as $Subcontractor_name)
      //                 $Subcontractor_name = (array)$Subcontractor_name;
                       echo "<option value = '".$Subcontractor_name->subcontractorID."}'>".  $Subcontractor_name->subcontractorNAME."</option>";
            <input type ="submit" name="query_submit" value ="Search" />


    <script type="text/javascript">

// make Dropdownlist depend on each other

 // depend owner name on site name  
     var arrayId = $(this).val().split(",");
     if(arrayId != ""){
       var ownerID = arrayId[0];
       var companyID = arrayId[1];

      url:"<?php echo get_stylesheet_directory_uri(); ?>/dropdown_fetch_owner.php",
                 var Response = data.split("--");





Read more here: how to use sql query with dropdown list?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: