javascript - php mysql and pagination -
i have problem displaying data mysql database. client requires display paginated data - i.e.15 rows per page, there sholdn't scrollers, , @ same time, data displayed ordered category , each new category have add 2 new rows @ table displayed in php file, sth. like:
r1-category1 r2-item name | item data1 ... db-item1 db-item2 ...new item x r1-category2 r2-item name | item data1 ... db-item 1 db-item 2
...
i tried call data database, each category added 2 new rows (such name of category , th items displayed), put them in array, counting rows , divided pages 15 results on it, , continue processing javascript. cons of method is, here lot of data , takes minute job done.
the best solution - data displayed asap imo use pagination, need define limit .. , there problem - how can define limit if categories among 15 results can various (sometimes 3, 4 or one) ? tried find out how many categories within 15 results database, make call database limit = limit-2x(no of categories) ... first page works fine, next pages not, obvious ... example: in limit of 15 rows example 3 categorires , need change limit 9 ... if change limit 9row, there 2 categories ... complicated, point is, cannot work point of view.
do have idea how solve this?
the first solution unacceptable customer, , second impossible point of view .. opinion in programming possible ..
get 15 items database (limit (start, count)
). remember starting index, , tag rows indexes. build table, each time encounter heading, subtract 2 number of rows show. when reach maximum table height, remember item would have displayed next: starting index next page.
stepping backwards trickier; need remember starting index of page came in order (if don't, have fetch all rows ones you're displaying). problem method won't know how many pages there beforehand.
an alternative write query gives row counts each category. fetching shouldn't take whole minute if have proper indexes in place, , if expensive, can cache results. information, can chunk data pages of 15 lines, using whole categories (provided no category has more 13 entries). can cache pagination data. downsides of method may have outdated pagination, when there lot of inserting , deleting going on, may end 16 or 17 lines instead of 15.
on side note, need educate customer bit. it's great good, don't want give impression possible in finite time.
Comments
Post a Comment