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.
listing_id
viewed be serialized?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.
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.