如何在Wordpress上使用php从MYSQL数据库中检索数据?
我有一个包含4个下拉列表的表,其中每个下载列表都包含从数据库中检索的数据,我希望用户从4个下拉列表中进行选择,并根据用户的选择我将在第二个表中显示所有相关字段请求。
所以我编写了一个从5个表中检索数据的查询。
但系统显示警告,不显示任何内容。
警告:mysqli_num_rows()期望参数1为mysqli_result,array ..
代码:
<?php
/*
Template Name: search info
*/
get_header();
?>
<?php
// code for submit button ation
global $wpdb,$_POST;
//variables that handle the retrieved data from mysql database
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="";}
$site_id = ['siteID'];
$equipment_type = ['equipmentTYPE'];
$lat=['latitude'];
$long=['longitude'];
$height = ['height'];
$owner_contact = ['ownerCONTACT'];
$sub_contact = ['subcontractorCONTACT'];
$sub_company = ['subcontractorCOMPANY'];
if(isset($_POST['query_submit']))
{
// 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`
");
If(mysqli_num_rows($query_submit)>0)
{
while($row=mysql_fetch_array($query_submit))
{
?>
<table width="30%" >
<tr>
<td>Site Name</td>
<td>Owner Name</td>
<td>Company Name</td>
<td>Subcontractor Name</td>
</tr>
<tr>
<td><?php echo $row['site_name']; ?></td>
<td><?php echo $row['owner_name']; ?></td>
<td><?php echo $row['company_name']; ?></td>
<td><?php echo $row['Subcontractor_name']; ?></td>
<td><?php echo $row['site_id']; ?></td>
<td><?php echo $row['equipment_type']; ?></td>
<td><?php echo $row['lat']; ?></td>
<td><?php echo $row['long']; ?></td>
<td><?php echo $row['height']; ?></td>
<td><?php echo $row['owner_contact']; ?></td>
<td><?php echo $row['sub_contact']; ?></td>
<td><?php echo $row['sub_company']; ?></td>
</tr>
</table>
<?php
}
}
}
?>
<?php
get_footer();
?>
我将不胜感激。