我正在创建一个网页,在前4个下拉列表中为用户显示,其中包含从MYSQL数据库中检索的数据。其中每个下拉列表代表不同表中的1列。
我正在使用wordpress和 $ wpdb 类
我需要的是能够根据用户选择向用户显示结果。
示例:
site id - site name - owner name - owner contact - lat - long - company name....
以及所有相关列。
问题是系统只显示在下拉列表中选择的数据......看起来系统只是从下拉列表中返回数据,而不是从数据库中返回数据。
我该如何解决这个问题?
我将显示部分代码和网页图片。
代码:
<?php
/*
Template Name: search info
*/
get_header();
?>
<?php
// code for submit button ation
global $wpdb;
//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="";}
//query to retrieve all related info of the selected data from the dropdown list
$query_submit =$wpdb->get_results ("select
site_info.siteID,site_info.siteNAME ,site_info.equipmentTYPE,site_coordinates.latitude,site_coordinates.longitude,site_coordinates.height ,owner_info.ownerNAME,owner_info.ownerCONTACT,company_info.companyNAME,subcontractor_info.subcontractorCOMPANY,subcontractor_info.subcontractorNAME,subcontractor_info.subcontractorCONTACT from `site_info`
LEFT JOIN `owner_info`
on site_info.ownerID = owner_info.ownerID
LEFT JOIN `company_info`
on site_info.companyID = company_info.companyID
LEFT JOIN `subcontractor_info`
on site_info.subcontractorID = subcontractor_info.subcontractorID
LEFT JOIN `site_coordinates`
on site_info.siteID=site_coordinates.siteID
where
site_info.siteNAME = `$site_name`
AND
owner_info.ownerNAME = `$owner_name`
AND
company_info.companyNAME = `$company_name`
AND
subcontractor_info.subcontractorNAME = `$Subcontractor_name`
" , ARRAY_A);
$site_id = 'siteID';
$site_id = (array)$site_id;
$equipment_type = 'equipmentTYPE';
$equipment_type = (array)$equipment_type;
$lat='latitude';
$lat = (array)$lat;
$long='longitude';
$long = (array)$long;
$height = 'height';
$height = (array)$height;
$owner_contact = 'ownerCONTACT';
$owner_contact = (array)$owner_contact;
$sub_contact = 'subcontractorCONTACT';
$sub_contact = (array)$sub_contact;
$sub_company = 'subcontractorCOMPANY';
$sub_company = (array)$sub_company;
?>
<table width="30%" >
<tr>
<td>Site Name</td>
<td>Owner Name</td>
<td>Company Name</td>
<td>Subcontractor Name</td>
<td>Site ID</td>
<td>Equipment Type</td>
<td> Lattitude</td>
<td>Longitude </td>
<td> Height</td>
<td> Owner Contact</td>
<td> Sub Contact</td>
<td> Sub company Name</td>
</tr>
<tr>
<?php
foreach ($query_submit as $query)
{
echo "<table>";
echo "<tr>";
echo "<td>" ,$query[siteNAME]. "</td>";
echo "<td>", $query[ownerNAME] ."</td>";
echo "<td>", $query[companyNAME] ."</td>";
echo "<td>", $query[subcontractorNAME]. "</td>";
echo "<td>" ,$query[siteID ]."</td>";
echo "<td>" ,$query[equipmentTYPE]. "</td>";
echo "<td>" ,$query[latitude]. "</td>";
echo "<td>" ,$query[longitude]. "</td>";
echo "<td>" ,$query[height]. "</td>";
echo "<td>" ,$query[ownerCONTACT]. "</td>";
echo "<td>" ,$query[subcontractorCONTACT ]."</td>";
echo "<td>" ,$query[subcontractorCOMPANY]. "</td>";
echo "</tr>";
echo"</table>";
}
?>
</tr>
</table>
<?php
}
?>
点击提交按钮后,没有显示任何内容......错误在哪里?
答案 0 :(得分:0)
我修复了使用echo显示错误的问题..我应该使用这种格式 echo&#34;&#34;。$ obj-&gt; siteNAME。&#34;&#34 ;; 强>
感谢您的回答和评论