dongwei1954 2011-08-16 12:55
浏览 7
已采纳

如何找到。是否插入了新记录?

I have the trouble to find is any new record is inserted in table.

My problem

I am developing Penny auction site. In my site, I'm updating client side view every second using JQuery ajax.last bidder username, avater, price and many things were update.But when the bid is placed I want to apply flash effect for particular product live here. I tried the following Mysql query to find if any last bid is placed.

  SELECT   CASE  WHEN  COUNT(*)=0 THEN 'N' WHEN  COUNT(*) > '0' THEN 'Y'
   END AS is_bid  FROM table_bid_history WHERE product_id = '$value' AND 
   ( date_time BETWEEN DATE_SUB(NOW(), INTERVAL 1 SECOND) AND  NOW()  )

Basically, I'm storing last bidder details in table_bid_history table with time stamp column date_time. I'm sending ajax request every second to server side to get last update using recursive function. So my idea was minus 1 second checks correct time so I used ( date_time BETWEEN DATE_SUB(NOW(), INTERVAL 1 SECOND) AND NOW() ) and it Works. But in some case, delayed ajax polling makes this idea false, which means some time ajax request takes more than 1 second so I'm unable to get correct result from server. If I make INTERVAL 2 SECOND, then it gives Y for two times. So I'm confused what to do in this situation.

Please help me to get last activity in table. How they doing it. Any idea would be appreciated !

Thanks in advance

  • 写回答

1条回答 默认 最新

  • doukang7501 2011-08-16 13:13
    关注

    Instead of querying whether there was a bid in the last second, query if there was any new bid since the last known bid. So, in your jQuery code, store the date_time of the last bid that you know of. Then, though AJAX, see if there are any bids in your table_bid_history that have a date_time newer than the date_time stored in your jQuery script. If there are, flash for effect (and of course, store the newer date_time for more querying later on).

    PS: You may want to look into long polling. That may be better on resources than frantically re-checking every second.

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

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂