mercredi 28 juin 2017

how to check if variable is empty or not in php and if its no need to display it in the table

i have PHP code with MYSQL database where the code fetch and select the required values and display it in a table.

what i need is to make a check before the display if the variable is empty do not display in the table.

for this i used the if statement but its not working.

code:

$sql = $wpdb->prepare("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 = %s
    AND 
    o.ownerID = %d
    AND 
    x.companyID = %d
   ",$site_name,$owner_name,$company_name);

 $query_submit =$wpdb->get_results($sql, OBJECT);

    echo "<br>";
    echo "<br>";

foreach ($query_submit as $obj) {

  echo "<table class='t1' width='30%'> ";
  echo     "<tr>";
  echo           "<th>Site ID</th>";
  echo           "<th>Site Name</th>";
  echo           "<th> Lattitude</th>";
  echo           "<th>Longitude </th>";
  echo           "<th>Owner Name</th>";
  echo           "<th>Company Name</th>";
  if(isset ($obj->equipmentTYPE))
  { 
     echo "<th>Equipment Type</th>";


  } 
  else { echo ''; } 

  if(isset ($obj->ownerCONTACT))
  { 
     echo "<th>Owner Contact</th>";


  } 
  else { echo ''; } 

  echo   "</tr>";  
  echo   "<tr>";   
  echo         "<td>".$obj->siteID."</td>";
  echo         "<td>".$obj->siteNAME."</td>";
  echo         "<td>".$obj->latitude."</td>";
  echo         "<td>".$obj->longitude."</td>";
  echo         "<td>".$obj->ownerNAME."</td>";
  echo         "<td>".$obj->companyNAME."</td>";
  if(isset ($obj->equipmentTYPE))
  { 
     echo "<td>".$obj->equipmentTYPE."</td>";


  } 
  else { echo ''; } 

  if(isset ($obj->ownerCONTACT))
  { 
    echo "<td>".$obj->ownerCONTACT."</td>";


  } 
  else { echo ''; } 

  echo   "</tr>";            


}

?>

Aucun commentaire:

Enregistrer un commentaire