php - 最新访问的模块无法正常工作
问题描述
需要最新访问用户的帮助。
问题是,如果我访问该广告 2 或 3 次,那么最近访问的模块会显示相同的广告 3 次或更多,如图所示。我需要我访问的广告只出现在顶部一次,并且只有日期和位置发生变化,但不重复。
MYSQL:
DROP TABLE IF EXISTS `class_latest_visited_ads`;
CREATE TABLE `class_latest_visited_ads` (
`id` int(10) NOT NULL,
`ad_id` int(10) DEFAULT NULL,
`date` datetime DEFAULT NULL,
KEY `idx_id` (`id`),
KEY `idx_ad_id` (`ad_id`),
KEY `idx_date` (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
INSERT INTO class_latest_visited_ads VALUES
('363', '25', '2021-03-05 09:21:23'),
('363', '73', '2021-03-05 09:21:44'),
('363', '60', '2021-03-05 09:21:55'),
('363', '48', '2021-03-05 09:22:03'),
('363', '39', '2021-03-05 09:22:27'),
('363', '65', '2021-03-05 09:24:15'),
('364', '73', '2021-03-05 10:12:07'),
('363', '69', '2021-03-05 10:57:34'),
('365', '56', '2021-03-05 11:20:48'),
('366', '56', '2021-03-05 15:48:53'),
('367', '56', '2021-03-05 20:09:40'),
('368', '56', '2021-03-06 13:29:34'),
('368', '54', '2021-03-06 15:38:10'),
('400', '70', '2021-03-14 22:24:20');
代码:
function getLatestVisited($where_str, $page, $no_per_page) {
if(isset($_COOKIE['ox_latest_visited_id']) && $_COOKIE['ox_latest_visited_id']) {
$lv_id = $_COOKIE['ox_latest_visited_id'];
}
global $settings, $ads_settings, $config_table_prefix;
$locations_str="";
if($settings['enable_locations'])
$locations_str = locations::makeQueryStr();
$listing = new listings();
$start=($page-1)*$no_per_page;
$where = " where ".TABLE_ADS.".active = 1";
$where .= $where_str.$locations_str;
$order_by_str = "order by ".$config_table_prefix."latest_visited_ads.`date`";
$join = "right join `".$config_table_prefix."latest_visited_ads` on ".$config_table_prefix."ads.id = ".$config_table_prefix."latest_visited_ads.ad_id";
$result=$listing->getShortListings($where,$order_by_str,'desc',$start, $no_per_page, '', '', $join);
return $result;
}
解决方案
推荐阅读
- sql-server - PowerShell:授予用户连接数据库引擎的权限
- javascript - 有没有办法让 NextJS 整个应用程序中的对象保持活动状态
- angular - JEST:尽管使用了未知组件,但单元测试成功
- python - Dash -Datatable 中具有多个输入(输入和下拉菜单)的回调
- javascript - 无法映射并获取对象数组中存在的数据
- reactjs - 如何修复错误代码:422(无法处理的实体)?
- javascript - 为什么我的计算机无法识别我的 HTML 画布元素?
- html - 如何在html内的markdown中使用脚注?
- javascript - 如何在 uplot 中添加参考线?
- javascript - 从 for 循环数组多次发送文本