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.
- Will each user have a single row be better, with the
listing_id
viewed be serialized? - Should I use cookies(automatically saved into database by Codeigniter?) instead?
- 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.