我有一个简单的表单,在我的 DataSource 中我创建了一个经典的displayMethod(名为 calculateAmount )并使用这个metodod在Form的网格中显示值
因此,我们只能显示来自 calculateAmount 的具有特定值的记录,例如我想只显示记录 calculateAmount()> 0,其他记录计算 calculateAmount()< 0没有显示。
所以,如果我不能混合使用Query和displayMethod,可能会在哪里插入条件(例如 active executeQuery 等)?
感谢您的建议。
答案 0 :(得分:2)
考虑以下顺序:
execute query
因此,您无法根据显示方法值在executeQuery
上添加查询范围。
你可以做的一件事:
if ([your data source].calculateAmount() > 0)
{
// do not add the record in temp table
}
else
{
// add the record in temp table
}
方法中编写逻辑以填充此新创建的表您可以在此处添加以下条件:
<?php
/*
Template Name: search info
*/
get_header();
?>
<?php
// code for submit button ation
if(isset($_POST['submit']))
{
//needed code
$site_name=$_POST['site_name'];
$owner_name=$_POST['owner_name'];
$company_name=$_POST['Company_name'];
$Subcontractor_name=$_POST['Subcontractor_name'];
?>
<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 $site_name ; ?></td>
<td><?php echo $owner_name ; ?></td>
<td><?php echo $company_name ; ?></td>
<td><?php echo $Subcontractor_name ; ?></td>
</tr>
</table>
<?php } ?>
<!--create dropdown list site names-->
<form method = "POST" action = ''>
<table width="30%">
<tr>
<td>Site Name</td>
<td>Owner Name</td>
<td>Company Name</td>
<td>Subcontractor Name</td>
</tr>
<tr>
<td><select id="site_name" name = 'site_name'>
<?php
$query_site_name =$wpdb->get_results ("select DISTINCT siteNAME from site_info");
foreach($query_site_name as $site_name)
{
$site_name = (array)$site_name;
echo "<option value = '{".$site_name ['siteNAME']."}'>". $site_name['siteNAME']."</option>";
}
?>
<!--create dropdown list owner names-->
</select></td>
<td><select id="owner_name" name = 'owner_name'>
<?php
$query_owner_name =$wpdb->get_results ("select DISTINCT ownerNAME from owner_info");
foreach($query_owner_name as $owner_name)
{
$owner_name = (array)$owner_name;
echo "<option value = '{".$owner_name ['ownerNAME']."}'>". $owner_name['ownerNAME']."</option>";
}
?>
</select></td>
<!--create dropdown list Company names-->
</select></td>
<td><select id="Company_name" name = 'Company_name'>
<?php
$query_Company_name =$wpdb->get_results ("select DISTINCT companyNAME from company_info");
foreach($query_Company_name as $Company_name)
{
$Company_name = (array)$Company_name;
echo "<option value = '{".$Company_name ['companyNAME']."}'>". $Company_name['companyNAME']."</option>";
}
?>
</select></td>
<!--create dropdown list Subcontractor names-->
</select></td>
<td><select id="Subcontractor_name" name = 'Subcontractor_name'>
<?php
$query_Subcontractor_name =$wpdb->get_results ("select DISTINCT subcontractorNAME from subcontractor_info");
foreach($query_Subcontractor_name as $Subcontractor_name)
{
$Subcontractor_name = (array)$Subcontractor_name;
echo "<option value = '{".$Subcontractor_name ['subcontractorNAME']."}'>". $Subcontractor_name['subcontractorNAME']."</option>";
}
?>
</select></td>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<input type = "submit" name="submit" value = "Search">
</td>
</tr>
</table>
</form>
<?php
get_footer();
?>
将临时表设置为网格的数据源。
希望这会有所帮助!!