php - Tablesorter reload tbody or only that row on database change/update -
i have seen lot of examples of tablesorter triggering update when user want's add or remove row in table see if it's possible reload entire row or tbody if there change in database ?
this thinking please let me know if idea or not.
the setup in javascript , php:
1. when page first loads script go , (.php) page display lastupdate (eg: '2013-07-18 10:37:29') .php page going database (mysql) , lastupdate , display it) lastupdate info (date/time) saved in var use later.
2. add timer ping same (.php) page , compare it's lastupdate vs initial lastupdate got when page first loaded.
3. keep pinging every x amount of seconds (maybe 10 sec) sniff changes lastupdate in database.
4. (compare): if initial lastupdate value less 1 got database mean content of database has been changed , 1 of 2 possible things.
what love point is:
option 1: remove old row , replace updated one. every row has unique id javascript can id# , update row in table.
or
option 2: delete current tbody , reload entire tbody new data.
the table has lot of rows/colums , uses images,hrefs, , on... each row heavy row , why use option 1 if possible, but don't know how last part!?
(unlike chat program) rows don't have in right order, long know id's updated in database.
let's have address book users can edit/update, add, remove contacts , contact info., want scan changes , when change found send id , data of row database row in table matching via id , update or delete old 1 , replace new one, if id not found in database remove id table since it's no longer in database.
so problem can run more 1 user made changes @ same time (like @ exact sec.) , 1 update show. think possible bypass checking database if there other different id's exact date/time , if there update them also.
thank reading , provide me.
use websockets and/or server push. if have 1000 clients, 0.1*1000=100 requests per second. not sure server side okay that.
when using websockets or server push, on event of database updating (someone updates should throw event), server sends clients:
- the order of database rows (they have unique ids)
- the rows has changed
it better use different php update clients. java servlets, example. maybe, task of updating db rows on client side, mean, can keep initial php page.
answering @compcobalt: simplifying, u receive 2 data types via websockets.
- jsonencoded array
- xml document containing table rows
here array: [47,27,1001,36,4,833,5,98,478,...]. array contains all ids of database rows in right order. right order may be, e. g., order of rows in database. javascript immediatly modifies html table correspond order. if before there row#26 , there no such row in array, javascript deletes it.
<tr data-id="47">...</tr><tr data-id="27">...</tr><tr data-id="1001">...</tr> even if js not know row#1001 or if row#27 has been updated. then, takes xml document (or json too, or format like) , parses it.
here gets content of updated row#27 , new row#1001 , fills table rows content.
then, starts waiting of new server push.
Comments
Post a Comment