table('search_keyword') . "WHERE keyword LIKE '%" . mysql_like_quote($keyword) . "%' OR pinyin_keyword LIKE '%" . mysql_like_quote($keyword) . "%' ORDER BY count DESC"; $result = $db->selectLimit($sql, 10); //查询分类 $sql = "SELECT cat_id, cat_name, parent_id FROM " . $ecs->table('category') . " WHERE cat_name LIKE '%" . mysql_like_quote($keyword) . "%' OR pinyin_keyword LIKE '%" . mysql_like_quote($keyword) . "%' $children limit 0,4"; $cate_res = $db->getAll($sql); $cat_html = ''; foreach ($cate_res as $key => $row) { if ($row['parent_id'] > 0) { $sql_1 = "SELECT cat_name FROM " . $ecs->table('category') . "WHERE cat_id=" . $row['parent_id']; $parent_res = $db->getRow($sql_1); $url = build_uri('category', array('cid' => $row['cat_id'])); if ($url == "") { $url = '#'; } $cat_html .= '
  • ' . "   在" . $parent_res['cat_name'] . ">" . $row['cat_name'] . "" . '分类下搜索
  • '; } } $html = ''; if ($html == '') { $html = ''; } echo $html; exit; } $len = 10 - $res_num; for ($i = 0; $i < $len; $i++) { if ($res_count == $i) { break; } $scws_res = scws($keyword_res[$i]['goods_name']); //这里可以把关键词分词:诺基亚,耳机 $arr = explode(',', $scws_res); $operator = " AND "; //@author guan end $keywords = 'AND ('; $goods_ids = array(); foreach ($arr AS $key => $val) { if ($key > 0 && $key < count($arr) && count($arr) > 1) { $keywords .= $operator; } $val = mysql_like_quote(trim($val)); //$sc_dsad = $_REQUEST['sc_ds'] ? " OR goods_desc LIKE '%$val%'" : ''; $keywords .= "(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)"; $sql = 'SELECT DISTINCT goods_id FROM ' . $ecs->table('tag') . " WHERE tag_words LIKE '%$val%' "; $res = $db->query($sql); while ($rows = $db->FetchRow($res)) { $goods_ids[] = $rows['goods_id']; } } $keywords .= ')'; $count = $db->getOne("SELECT count(*) FROM " . $ecs->table('goods') . " WHERE is_delete=0 AND is_on_sale=1 AND is_alone_sale=1 $keywords"); if ($count <= 0) { continue; } if (in_array($keyword_res[$i]['goods_name'], $exist_keyword)) { continue; } $keyword_new_name = $keyword_res[$i]['goods_name']; cut_str($keyword_new_name, 25); $keyword_style = preg_replace("/($keyword)/i", "$1", $keyword_new_name); $html .= '
  •  ' . $keyword_style . '
     ' . '' . '
    约' . $count . '个商品
  • '; } } $html .= ''; if ($html == '') { $html = ''; } echo $html; exit; } /** * author : lihui870920@163.com * date : 2012-05-12 * 截取指定的中英文字符的长度 * * 指定字符串 * 保留长度 * 开始位置 * 编码 */ function cut_str($string, $sublen, $start = 0, $code = 'gbk') { if ($code == 'utf-8') { $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; preg_match_all($pa, $string, $t_string); if (count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen)) . "..."; return join('', array_slice($t_string[0], $start, $sublen)); } else { $start = $start * 2; $sublen = $sublen * 2; $strlen = strlen($string); $tmpstr = ''; for ($i = 0; $i < $strlen; $i++) { if ($i >= $start && $i < ($start + $sublen)) { if (ord(substr($string, $i, 1)) > 129) { $tmpstr.= substr($string, $i, 2); } else { $tmpstr.= substr($string, $i, 1); } } if (ord(substr($string, $i, 1)) > 129) $i++; } //超出多余的字段就显示... if (strlen($tmpstr) < $strlen) $tmpstr.= ""; return $tmpstr; } } ?>