首页 > 解决方案 > 最新访问的模块无法正常工作

问题描述

需要最新访问用户的帮助。

问题是,如果我访问该广告 2 或 3 次,那么最近访问的模块会显示相同的广告 3 次或更多,如图所示。我需要我访问的广告只出现在顶部一次,并且只有日期和位置发生变化,但不重复。

图片:2个第一次访问相同(复制)

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;

}

标签: phpmysqlsmarty

解决方案


推荐阅读