当你的自定义表单数据过多或者需要查询某个单时,给后台的自定义表单加个简单的搜索功能很有必要。
1、打开 \dede\templets\diy_main.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>\r\n"; } else { echo "<option value='{$k}'>{$fielddata[0]}</option>\r\n"; } } ?> </select> <input type='submit' name='sb' value='确定' class="coolbg np" /> </form> </div>
2、打开 \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);