自定义表单搜索

1601950842-ce0e58da6f1930d

当你的自定义表单数据过多或者需要查询某个单时,给后台的自定义表单加个简单的搜索功能很有必要。
 
实现教程
 
打开/dede/templets/diy_list.htm 找到
 
内容列表</div>
 
在它的下面加入
 
<div class=”bodytitletxt” style=”padding-left:10px;”>
<form name=’form1′ action=”diy_list.php”>
<input type=’hidden’ name=’action’ value=’list’ />
<input type=’hidden’ name=’diyid’ value='<?php echo $diy->diyid; ?>’ />
关键字:
<input type=’text’ name=’keyword’ size=’20’ value=”<?php echo $keyword; ?>” />
<select name=”field”>
<?php
foreach($fieldlist as $k=>$fielddata)
{
if($k==$field)
{
echo “<option value='{$k}’ selected>{$fielddata[0]}</option>rn”;
}
else
{
echo “<option value='{$k}’>{$fielddata[0]}</option>rn”;
}
}
?>
</select>
<input type=’submit’ name=’sb’ value=’确定’ class=”coolbg np” />
</form>
</div>
 
打开 /dede/diy_list.php 找到
 
$query = “SELECT * FROM {$diy->table} ORDER BY id DESC”;
 
if(empty($keyword))
{
$keyword = ”;
$addquery = ”;
}
else
{
$addquery = ” WHERE {$field} LIKE ‘%”.trim($keyword).”%’ “;
}
$query = “SELECT * FROM {$diy->table} $addquery ORDER BY id DESC”;
 
继续找到
 
$datalist->SetParameter(‘diyid’, $diyid);
 
在它的下面加入
 
$datalist->SetParameter(‘keyword’, $keyword);
$datalist->SetParameter(‘field’, $field);