I am using SE4 application of Zend framework. After executing query with Paginator, I am setting items per page like 10, 20, 50, all etc. using function setItemCountPerPage() of zend.
It is working fine for number provided or for zero value. But I have thousands of records and want to show all on single page without pagination.
I am using following code after query-
$this->view->paginator = Zend_Paginator::factory($select);
$this->view->paginator->setItemCountPerPage($perPage, 10);
$this->view->paginator->setCurrentPageNumber($this->_getParam('page',1));
Please let me know what value should I provide for $perPage, so all items fetched by query will get display on page.
You can simply pass the size of your list (http://php.net/manual/de/function.sizeof.php), or deactivate the pagination. But if you have thousands of records, it would be a good idea to load them in sequence, not all at once :) Probably with ajax on scroll to bottom of page (Load ajax when scroll reaches 80%).
Related
First, a quick explanation of my current situation:
My webpage contains a list of (about 40, categorized) filters and a list of 400+ products.
I get the list of products using Ajax. By default 20 products are shown, but when you scroll to the bottom more products are added. Users can filter the results by clicking the desired option. It's like a simplified ebay. Only difference is i don't reload the page when i click on a filter, but instead i use Ajax to get my products.
Now, ebay has these numbers next to every filter option, which shows the amount of results you'd get if you click that option. My question is, What is the best way to show these numbers?
My approach would be to run a sql query (SELECT COUNT(id) FROM sometable WHERE filter='something') for every filter option. However that means i have to run about 40 queries on load, and every time the user clicks an option (using Ajax). This seems like heavy server load, or am i wrong?
I'm going with my first approach, but now i'm using UNION queries to get all counts. This way i only have to run 1 query instead of 1 query for every filter.
I have notification list. Onclick view notification. I get all the notification info list. This is done by ajax call by passing notification id.
Now, I want to use pagination to display notification info.
Here is the problem:
I am using default pagination class provided by codeigniter. I am setting base_url like,
base_url().'notification'
The real page is: notification/display_notification_info. (This display notification info is done by ajax).
When I change base url for pagination then I will miss notification Id. And when I keep same base url as displayed above then I am not getting correct page link.
What should I do in this case to keep notification id (variable) through out pagination.
Can I pass that variable through pagination create link. But, I can't find way to pass external variable from those create links.
Thanks.
What you can do is just get rid of the pagination class (since you are using ajax to paginate) and keep track of your offset / limit (for database).
Just use a variable to keep track of offset, and do an ajax request for new data set (limit stays the same and returns you say 10 records, your offset is then 10, then 20, 30, etc;).
Pagination for CI only helps if you use the view, it creates the links for you automatically, otherwise you would just go through the limit + offset.
First off I would like to say that I have done ample research on jquery pagination tutorials and scripts and the ones I have tried had worked, but just not the way I wanted them to.
What I am looking for is a jquery+php pagination that has 5 buttons. One for the first page, last page, next page, previous page, and manually enter a page to go to (which would also display the current page). I am new to pagination and have no idea how to integrate or alter current scripts, but I'm willing to learn as long as I can have the 5 buttons stated above and use php mysql queries. Thanks for the help!
UPDATE: I can do this with only php (would have to reload the page) but I do not know how to do this with jquery
UPDATE2: I figured out how to have the user manually input page number, but I still do not know how to do the other for buttons. For the next and previous buttons, I think I need to return the current page, but I have no idea how to do this :/
The trick is you use limit and offset parameters in your mysql query. Depending on what page number of the result you are serving, you can modify the ordered mysql query to fetch the result from that offset. It's pretty simple to work with that after you understand how to paginate in mysql queries.
In order to accomplish this you simply need to enable your application to make an ajax call to fetch the 'more info' results. That ajax call should take two parameters, an OFFSET and a LIMIT. Simply store these values locally in the application (via hidden elements, JS cookies, etc) to reference. Next time the 'more info' button is pressed you increment the OFFSET by the LIMIT and repeat.
NOTE: It's important that your query that is fetching the results is also using an ORDER BY. If you are relying on the server to order the results the same automatically you could potentially repeat results if the data is being updated often.
I'm working for a client who asks me to prepare a module for its website (written using Yii) with the following features:
It shows 3 elements from a mysql_result, starting from offset=0.
The user can click on any of them to mark them as "read". That makes the desired item to disappear and to appear what would be the following item. That is, if you are showing items 3 4 5 and you click on 4, that item would disappear and appear the number 6, meaning the result would be 3 5 6.
The elements being shown are partial views and the button that "deletes" the item is a widget within each partial view.
The user can move through the list of items using some << and >> arrows to go back and forth the result.
One of the options the client gave to me was to show a list of pages ( 1 | 2 | 3 | 4... and so), but deleting items means the number of pages will decrease at some time in the future, plus if the amount is pretty big, I would need something more flexible such as only showing the current and other 4 pages at most. Another option is to keep the << and >> arrows.
I've tried to convince the client that pagination and a "live list" is a pretty bad idea, but he rejected the idea to limit the visualization to only the first 3 items (keeping in mind that eventually you will delete them and thus will be able to see the following items).
I'm developing it using Yii, MySQL and jQuery, and I'm not able to use CPagination because of this living list. I'm not asking the code, just some guidelines because I got lost the third time I tried doing it.
Some basics about the system:
I got a controller which loads the first 3 items of this module.
I got some actions in this controller that fetches the next item within a page (which may not be the same of the current object, though. One of my problems resides here), and the full page.
Each item is able to mark itself as "read", which will make the item not appearing the next time you fetch some results.
Every 1 second I check for items that have been marked as read, remove from DOM and append some new items using the action I defined in the second bullet.
Every time the user hits the << or >>, I reload the previous/next page (That would not be a problem apparently. If you're in the last page and there aren't more items to add, you just remain there. However if you empty the page, I don't have any method to detect that and scroll one page back).
As you may see, this headache would be easier without the pagination buttons, but the client obligues me to put them. What would you do guys? Thanks in advance
EDIT: The client decided to get the results in a random flavor. There is no more pagination, so the problem has disappeared. The #thaddeusmt answer may not have helped me really much, but I'll give it as valid, as it might be plenty useful for other people with similar problems than mine. Cheers
It seems to me like the CGridView or CListView should basically do this automatically. They support AJAX updating/paging out-of-the-box.
I assume that you have an AJAX action that like "actionMarkRead()" which you are calling when the user clicks. I assume that this sets some database field somewhere saying that the user has "Read" that item. To make this work with the CListView, just make sure that the CDataProvider has a condition which checks that "read" field (might have to JOIN a table, I don't know what your DB looks like). Then, when the list reloads via AJAX, it will have the correct # of pages to represent the smaller number of pages the CDataProvier query is returning.
I just tested this and it works!
The way I tested it is I set up a CGridView with 'ajaxUpdate'=>true,. Then in my CDataProvider I set 'pagination'=>1 to make it easy to test. Then I used the default AJAX actionDelete in my Controller to delete the items. Every time I deleted an item via that AJAX action link in the CGridView, the grid refreshed via AJAX and page count shrunk by 1. Seems to work like a charm!
Cheers and good luck!
i set my pagination with per_page=2. I have 5 records in my table.My 1 st page containd record 1,2 and my 2nd page containd the records 3,4 and my 3rd page containsthe record 5. I tried to delete the record in the 3rd page. After deleting it shows empty records list. But i want to move to the previous page. Is it possible in codeigniter pagination
There's nothing built in to the CI pagination class, you'll have to do it yourself.
Each time you run the controller method (load the page), check if the result set is empty (and the page is not 1 or zero), if so - redirect to the previous page, preferably by calculating the last page number and going straight to it (or you could end up with a lot of redirects if the user goes to page 9999).
This should work but I have not tested it.
$last_page = floor($this->pagination->total_rows / $this->pagination->per_page);
You may want to look into finding another way to handle pagination as well, the Codeigniter pagination library sucks. Wish I had a link to share with something better but I don't, best to google/write something yourself that fits your needs.
You need to check last link, if it equal 1 (all_rows - uri_segment) in your exsimple 5-4, after then uri_segment - rer_page (4-2 = 2) and redirect to your_site/uri_segment = 2. I think this is rigth case!