ECSHOP前台添加搜索问题功能
//lib_main.php
function assign_comment($id, $type, $type2=0, $page = 1,$search=false)
{
if($search){
$comment_where = (!empty($type2)) ? " AND content LIKE '%" . mysql_like_quote($type2) . "%' " : '';
}else{
$comment_where= (!empty($type2)) ? " AND comment_type2 = '".$type2."'" : '';
}
/* 取得评论列表 */
$count = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('comment').
" WHERE id_value = '$id' AND comment_type = '$type' $comment_where AND status = 1 AND parent_id = 0");
$size = !empty($GLOBALS['_CFG']['comments_number']) ? $GLOBALS['_CFG']['comments_number'] : 5;
$page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE id_value = '$id' AND comment_type = '$type' $comment_where AND status = 1 AND parent_id = 0".
' ORDER BY comment_id DESC';
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size);
$arr = array();
$ids = '';
while ($row = $GLOBALS['db']->fetchRow($res))
{
$ids .= $ids ? ",$row[comment_id]" : $row['comment_id'];
$arr[$row['comment_id']]['id'] = $row['comment_id'];
$arr[$row['comment_id']]['email'] = $row['email'];
$arr[$row['comment_id']]['comment_type2'] = $row['comment_type2'];
$arr[$row['comment_id']]['username'] = $row['user_name'];
$arr[$row['comment_id']]['content'] = str_replace('\r\n', '
', htmlspecialchars($row['content']));
$arr[$row['comment_id']]['content'] = str_replace('\n', '
', $arr[$row['comment_id']]['content']);
$arr[$row['comment_id']]['rank'] = $row['comment_rank'];
$arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
}
/* 取得已有回复的评论 */
if ($ids)
{
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE parent_id IN( $ids )";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetch_array($res))
{
$arr[$row['parent_id']]['re_content'] = str_replace('\n', '
', htmlspecialchars($row['content']));
$arr[$row['parent_id']]['re_add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
$arr[$row['parent_id']]['re_email'] = $row['email'];
$arr[$row['parent_id']]['re_username'] = $row['user_name'];
}
}
/* 分页样式 */
//$pager['styleid'] = isset($GLOBALS['_CFG']['page_style'])? intval($GLOBALS['_CFG']['page_style']) : 0;
$pager['page'] = $page;
$pager['size'] = $size;
$pager['record_count'] = $count;
$pager['page_count'] = $page_count;
$pager['page_first'] = "javascript:gotoPage(1,$id,$type,$type2)";
$pager['page_prev'] = $page > 1 ? "javascript:gotoPage(" .($page-1). ",$id,$type,$type2)" : 'javascript:;';
$pager['page_next'] = $page < $page_count ? 'javascript:gotoPage(' .($page + 1) . ",$id,$type,$type2)" : 'javascript:;';
$pager['page_last'] = $page < $page_count ? 'javascript:gotoPage(' .$page_count. ",$id,$type,$type2)" : 'javascript:;';
$cmt = array('comments' => $arr, 'pager' => $pager);
return $cmt;
}
//comment.php
/*
* act 参数不为空
* 默认为评论内容列表
* 根据 _GET 创建一个静态对象
*/
$cmt = new stdClass();
$cmt->id = !empty($_GET['id']) ? intval($_GET['id']) : 0;
$cmt->type = !empty($_GET['type']) ? intval($_GET['type']) : 0;
//$cmt->type2 = !empty($_GET['type2']) ? intval($_GET['type2']) : 0;
if(isset($_GET['type2'])){
$cmt->type2 = !empty($_GET['type2']) ? intval($_GET['type2']) : 0;
$search=false;
}else{
$cmt->type2 = !empty($_GET['keyword']) ? trim($_GET['keyword']) : 0;
$cmt->type2 = iconv("UTF-8","GB2312",$cmt->type2);
$search=true;
}
$cmt->page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
}
if ($result['error'] == 0)
{
$comments = assign_comment($cmt->id, $cmt->type, $cmt->type2, $cmt->page,$search);
//因为之前做了评论分频道 所以TYPE2为列表的定位 现在用来做KEYWORDS的入口给 assign_comment 函数
//最后是JS
function searchComment()
{
var keyword = document.getElementById('zx_search').value;
if (keyword.length > 0)
{
Ajax.call('comment.php?act=gotopage', 'page=' + 1 + '&id=' + {$id} + '&type=' + {$comment_type} + '&keyword=' + keyword, gotoPageResponse, 'GET', 'JSON');
}
else
{
document.getElementById('zx_search').focus();
}
}
//lib_main.php
function assign_comment($id, $type, $type2=0, $page = 1,$search=false)
{
if($search){
$comment_where = (!empty($type2)) ? " AND content LIKE '%" . mysql_like_quote($type2) . "%' " : '';
}else{
$comment_where= (!empty($type2)) ? " AND comment_type2 = '".$type2."'" : '';
}
/* 取得评论列表 */
$count = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('comment').
" WHERE id_value = '$id' AND comment_type = '$type' $comment_where AND status = 1 AND parent_id = 0");
$size = !empty($GLOBALS['_CFG']['comments_number']) ? $GLOBALS['_CFG']['comments_number'] : 5;
$page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE id_value = '$id' AND comment_type = '$type' $comment_where AND status = 1 AND parent_id = 0".
' ORDER BY comment_id DESC';
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size);
$arr = array();
$ids = '';
while ($row = $GLOBALS['db']->fetchRow($res))
{
$ids .= $ids ? ",$row[comment_id]" : $row['comment_id'];
$arr[$row['comment_id']]['id'] = $row['comment_id'];
$arr[$row['comment_id']]['email'] = $row['email'];
$arr[$row['comment_id']]['comment_type2'] = $row['comment_type2'];
$arr[$row['comment_id']]['username'] = $row['user_name'];
$arr[$row['comment_id']]['content'] = str_replace('\r\n', '
', htmlspecialchars($row['content']));
$arr[$row['comment_id']]['content'] = str_replace('\n', '
', $arr[$row['comment_id']]['content']);
$arr[$row['comment_id']]['rank'] = $row['comment_rank'];
$arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
}
/* 取得已有回复的评论 */
if ($ids)
{
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE parent_id IN( $ids )";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetch_array($res))
{
$arr[$row['parent_id']]['re_content'] = str_replace('\n', '
', htmlspecialchars($row['content']));
$arr[$row['parent_id']]['re_add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
$arr[$row['parent_id']]['re_email'] = $row['email'];
$arr[$row['parent_id']]['re_username'] = $row['user_name'];
}
}
/* 分页样式 */
//$pager['styleid'] = isset($GLOBALS['_CFG']['page_style'])? intval($GLOBALS['_CFG']['page_style']) : 0;
$pager['page'] = $page;
$pager['size'] = $size;
$pager['record_count'] = $count;
$pager['page_count'] = $page_count;
$pager['page_first'] = "javascript:gotoPage(1,$id,$type,$type2)";
$pager['page_prev'] = $page > 1 ? "javascript:gotoPage(" .($page-1). ",$id,$type,$type2)" : 'javascript:;';
$pager['page_next'] = $page < $page_count ? 'javascript:gotoPage(' .($page + 1) . ",$id,$type,$type2)" : 'javascript:;';
$pager['page_last'] = $page < $page_count ? 'javascript:gotoPage(' .$page_count. ",$id,$type,$type2)" : 'javascript:;';
$cmt = array('comments' => $arr, 'pager' => $pager);
return $cmt;
}
//comment.php
/*
* act 参数不为空
* 默认为评论内容列表
* 根据 _GET 创建一个静态对象
*/
$cmt = new stdClass();
$cmt->id = !empty($_GET['id']) ? intval($_GET['id']) : 0;
$cmt->type = !empty($_GET['type']) ? intval($_GET['type']) : 0;
//$cmt->type2 = !empty($_GET['type2']) ? intval($_GET['type2']) : 0;
if(isset($_GET['type2'])){
$cmt->type2 = !empty($_GET['type2']) ? intval($_GET['type2']) : 0;
$search=false;
}else{
$cmt->type2 = !empty($_GET['keyword']) ? trim($_GET['keyword']) : 0;
$cmt->type2 = iconv("UTF-8","GB2312",$cmt->type2);
$search=true;
}
$cmt->page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
}
if ($result['error'] == 0)
{
$comments = assign_comment($cmt->id, $cmt->type, $cmt->type2, $cmt->page,$search);
//因为之前做了评论分频道 所以TYPE2为列表的定位 现在用来做KEYWORDS的入口给 assign_comment 函数
//最后是JS
function searchComment()
{
var keyword = document.getElementById('zx_search').value;
if (keyword.length > 0)
{
Ajax.call('comment.php?act=gotopage', 'page=' + 1 + '&id=' + {$id} + '&type=' + {$comment_type} + '&keyword=' + keyword, gotoPageResponse, 'GET', 'JSON');
}
else
{
document.getElementById('zx_search').focus();
}
}
作者:noel@SEO
地址:http://www.laohucheng.com/post/415/
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!
ECSHOP-index_get_only_article 指定获取1篇文章
ecshop中调用smarty的foreach-iteration函数
2009
11:39
208
0


