best way for next/previous buttons for entries in yii -


I would like to know what is the best way to create next / previous buttons for entry into the database. Suppose we have images There is a table and the id and path of each image is. If the current image has an id equal to "9" then how can I get the next and previous ID?

I already found a solution for this right but it seems the latest option. If we have more than 10000 entries (images) in our database, then this server will be submerged first, it selects all the entries and then it tries to copy all the results in an array. After this, the array is searched for the current ID. It is very slow.

I was thinking about the limit set on the query, but after that how do I get the next and previous pictures?

Another (better, I think) solution will have to obtain the ID of the current photo and it will be reduced / increased unless another image is found with the new ID. I think it is faster than the given function in the link.

In addition to setting prev_id and next_id in the current picture model, there is one more idea in the same link but here we have only one problem, how do we find them? And even if we find them, then is it right to store data about the previous / next pictures in the current picture? It does not seem right, but I'm sure that when you want to access that data, it will be more convenient.

This query only returns the next / previous line, if found. Better? (Should be implemented in your model class).

  public function getNextId () {$ record = self :: model () - & gt; Find (Arrays ('condition' = & gt; 'id'; current_id '', 'order' => 'id asc', 'limit' => 1, 'params' => array ( ': Current_id' => $ this-> ID),);); If ($ record! == empty) $ record-> id; Return tap; } Public event getPreviousId () {$ record = self :: model () - & gt; Find (Arrays ('condition' = & gt; 'id & lt ;: current_id', 'order' => ID idc, 'border' = & gt; 1, 'params' => array ( ': Current_id' => $ this-> ID),);); If ($ record! == empty) $ record-> id; Return tap; }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -