Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

kueri sql tidak mengambil semua catatan hanya mengambil catatan terakhir

Pindahkan baris tabel Anda di dalam loop sementara dan baris judul Anda sebelum loop dan kemudian Anda akan melihat semua data dan bukan hanya baris terakhir

$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.ownerNAME = %s
    AND x.companyNAME = %s
   ",$site_name,$owner_name,$company_name);

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

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

// table that will dsiplay the results based on the user's selection //
echo "<table width='30%' ";
echo     "<tr>";
echo           "<td>Site Name</td>";
echo           "<td>Owner Name</td>";
echo           "<td>Company Name</td>";
echo           "<td>Subcontractor Name</td>";
echo           "<td>Site ID</td>";
echo           "<td>Equipment Type</td>";
echo           "<td> Lattitude</td>";
echo           "<td>Longitude </td>";
echo           "<td> Height</td>";
echo           "<td> Owner Contact</td>";
echo           "<td> Sub Contact</td>";
echo           "<td> Sub company Name</td>";
echo   "</tr>";  

foreach ($query_submit as $obj) {
    echo   "<tr>";        
    echo         "<td>".$obj->siteNAME."</td>";
    echo         "<td>".$obj->ownerNAME."</td>";
    echo         "<td>".$obj->companyNAME."</td>";
    echo         "<td>".$obj->subcontractorNAME."</td>";
    echo         "<td>".$obj->siteID."</td>";
    echo         "<td>".$obj->equipmentTYPE."</td>";
    echo         "<td>".$obj->latitude."</td>";
    echo         "<td>".$obj->longitude."</td>";
    echo         "<td>".$obj->height."</td>";
    echo         "<td>".$obj->ownerCONTACT."</td>";
    echo         "<td>".$obj->subcontractorCONTACT."</td>";
    echo         "<td>".$obj->subcontractorCOMPANY."</td>";
    echo  "</tr>";

} 

echo '</table>';   

?>


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara mendapatkan daftar pinggiran kota di sekitar lokasi lalu ulangi untuk lokasi lain menggunakan MySql?

  2. Kaskade INNODB saat dihapus dan diperbarui

  3. Mysql memilih dari dua tabel

  4. Dapatkan parameter url dan masukkan ke dalam database

  5. Panggilan balik MySQL - apakah ada yang seperti itu?