我有一个表log_Data
,我在其中记录用户输入的搜索关键字。我面临一个问题,即mysql查询多次插入数据。查询非常简单INSERT INTO TABLE_NAME (id, keyword, date_adde) ...
,但是如果用户输入一些单词...查询将插入它,几秒钟后它将再次插入,有时会插入相同的记录4 5次。
我该如何限制插入并使其更加准确,从而避免重复并获得更好,更准确的搜索报告。
编辑
在我的控制器内:
if(isset($this->request->get['search']) && $this->request->get['search'] != ' '){
$search_log = array(
'keyword' => $this->request->get['search'],
'source' => '0', //0 for website and 1 for application
'total_result' => $product_total
);
$this->model_catalog_product->searchLog($search_log);
}
在我的模型中,我有:
public function searchLog($data){
$query = $this->db->query("INSERT INTO search_log SET keyword = '" . $this->db->escape($data['keyword']) . "', record = '" . (int)$data['total_result'] . "', customer_id = '" . (int)$this->customer->getId() . "', source = '" . (int)$data['source'] . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', date_added = NOW()");
}
附上一张图片,其中顾客搜索heel
“以黑色突出显示”被插入7次,相差几秒钟...该顾客最初仅搜索1次...与其他词相同好吧...
答案 0 :(得分:0)
首先,检查您的代码。传出秘诀密钥:
md5(关键字+日期+小时)
答案 1 :(得分:0)