如何显示从 MYSQL 中检索到的所有数据 [英] how to display all the retrieved data from MYSQL
问题描述
使用 PHP &MYSQL on WordPress 和 Google Map API,以便从 MYSQL 数据库中检索数据并在 Google Map 上显示带有信息窗口的标记.
using PHP & MYSQL on WordPress and Google Map API in order to retrieve data from MYSQL database and display markers with info windows on Google Map.
问题是地图没有出现在网页上,但 SQL 查询正在检索所需的数据.
problem is that the map doesn't appear on the webpage, yet the SQL query is retrieving the required data.
我有 SQL 查询的地方:
where i have SQL query:
检索数据并将其显示在表格中
that retrieve data and display it in table
{
position: new google.maps.LatLng(33.8533166667, 35.5077833333),
info:'BIS001',
height: '48',
site_name: Bissan',
}
,{
position: new google.maps.LatLng(33.8533166667, 35.5077833333),
info:'BIS002',
height: '48',
site_name: Bissan',
}
,{
position: new google.maps.LatLng(33.8533166667, 35.5077833333),
info:'BIS003',
height: '48',
site_name: Bissan',
}
这必须显示在系统显示的网页上,而不是仅显示最后一个值:
this what must be displayed on the web page the system display instead just the last value:
Bissan Fadi El Moussawi gds BIS003
如何让系统或查询显示所有需要的记录?
how to make the system or the query display all the required records?
<?php
// code for submit button action
global $wpdb, $site_name;
//variables that handle the retrieved data from mysql database based on the ID of the variable in HTML (select)
if(isset($_POST['query_submit']))
{
if(isset($_POST['site_name']))
{
$site_name=$_POST['site_name'];
}
else { $site_name=""; }
if(isset($_POST['owner_name']))
{
$owner_name=$_POST['owner_name'];
}
else { $owner_name=""; }
if(isset($_POST['Company_name']))
{
$company_name=$_POST['Company_name'];
}
else { $company_name=""; }
if(isset($_POST['Subcontractor_name']))
{
$Subcontractor_name=$_POST['Subcontractor_name'];
}
else { $Subcontractor_name="";}
// var_dump($site_name);
$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>";
//echo $sql;
// var_dump($_POST['site_name']);
foreach ($query_submit as $obj) {
$obj->siteNAME;
$obj->ownerNAME;
$obj->companyNAME;
$obj->subcontractorNAME;
$obj->siteID;
$obj->equipmentTYPE;
$obj->latitude;
$obj->longitude;
$obj->height;
$obj->ownerCONTACT;
$obj->subcontractorCONTACT;
$obj->subcontractorCOMPANY;
}
// 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>";
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 "<tr>";
echo "<td>";
?>
推荐答案
'Bissan' 之前的文本标识符 (') 总是缺失.尝试在字符串前后使用文本标识符.像这样:
The text identifier (') right before 'Bissan' is always missing. Try it with text identifier before and after the string. Like that:
{
position: new google.maps.LatLng(33.8533166667, 35.5077833333),
info:'BIS001',
height: '48',
site_name: 'Bissan',
}
,{
position: new google.maps.LatLng(33.8533166667, 35.5077833333),
info:'BIS002',
height: '48',
site_name: 'Bissan',
}
,{
position: new google.maps.LatLng(33.8533166667, 35.5077833333),
info:'BIS003',
height: '48',
site_name: 'Bissan',
}
这篇关于如何显示从 MYSQL 中检索到的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!