dounai9294 2012-04-07 23:53
浏览 49
已采纳

跟踪上次查看的访问者项目

I have a very AJAX-ish listing webpage created using Codeigniter where I want registered users to be able to differentiate which listings they have viewed previously.

Current Attempt: On clicking the listing, the listing id is sent vis $.post() to serverside PHP, which inserts(using INSERT... ON DUPLICATE KEY UPDATE) the listing_id, user_id, view_timestamp into a table with viewed_id on autoincrement. Everytime the visitor does a new search, all the listing_id with his user_id is retrieved from the MySQL table via .getJSON(), and through a loop, the CSS of these previously viewed listings are changed.

My conern is whether this method involves too much work on the server.

  1. Will each user have a single row be better, with the listing_id viewed be serialized?
  2. Should I use cookies(automatically saved into database by Codeigniter?) instead?
  3. Insert new listings viewed via AJAX when user views it. But only retrieves the list of viewed listings' id once if cookie containing all the viewed listing ids does not exist, else after sending newly viewed listings to the server to be inserted, the listing id is also inserted into the cookie. This way after doing new searches, there is no need to continuously query the database for the entire list of viewed listing ids.

Note: For an estimate of number of AJAX requests for previously viewed listings' listing_id, average user will do a new search every 20 secs.

  • 写回答

1条回答 默认 最新

  • dongpa5207 2012-04-08 10:06
    关注

    Spontaneously for this kind of functionality I wouldn't involve the database and look at client-side solutions instead, like storing Json with the data using localStorage or alternatively cookies if you want wider browser support (or need to store it from your php-code and can't do it from the javascript). If you have to store this information in your database, I would still look at solutions to cache the information on the client as much as possible, like how you described it in point 3.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向