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

EX:

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.

code:

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


                     $query_site_name =$wpdb->get_results("select DISTINCT 
                        i.siteNAME, 
                        i.ownerID, 
                        i.companyID,
                        o.ownerNAME,
                        x.companyNAME
                       from site_info i
                       LEFT  
                       JOIN owner_info o
                       on i.ownerID = o.ownerID
                       LEFT  
                       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>";
                      } 

                 ?>

                </select></td>

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

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

<!--create  dropdown list Subcontractor names-->
                <td><select id="Subcontractor_name"  name ="Subcontractor_name">
                <?php 
                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>";
                      } 
                   ?>
                </select></td>
            <tr>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td>
            <input type ="submit" name="query_submit" value ="Search" />

        </td>
       </tr>

        </table>
    </form>
    <script type="text/javascript">

// make Dropdownlist depend on each other
$(document).ready(function(){


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

     $.ajax({
      url:"<?php echo get_stylesheet_directory_uri(); ?>/dropdown_fetch_owner.php",
       method:"POST",
       data:{ownerID:ownerID,companyID:companyID},
       datatype:"text",
       success:function(data){
                 var Response = data.split("--");
                 $('#owner_name').html(Response[2]);
                 $('#Company_name').html(Response[4]);
        }
     });


   }


  });

});

</script>

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


Solution:

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: