php - CakePHP: Find a record and retrieve the 10 following records -


i developing tool can 10 records big table, based on input in form. example, if table has column record "number", can input 1 number , app return 10 following records record number.

the porpuse of lastest 10 inputs from last fetch.

the problem that, afaik, there's no way make find condition of starting search @ specific position.

find neighbors quite close, unfortunately returns 2 results: previous , next 1 search.

any ideas?


edit: right query looks this:

 $data = $this->tweet->find('all', array(    'field' => array('tweet.permalink' => $param2),    'fields' => array('tweet.embed'),    'limit' => 10,    'order' => array('tweet.created' => 'desc'),    'contain' => false,    // 'offset' => 1,    'conditions' => array('not' => array('tweet.embed' => null),     'tweet.status' => 'approved',     ),  )); 

doesn't work way like. if don't comment first line ("field") return 1 result. btw, $param2 input of user


edit edit: the dirty solution.

i used nunser approach. didn't understand findneighbors function after debugging function ended this:

protected function _findneighbors($state, $query, $results = array()) {     extract($query);      if ($state === 'before') {         $conditions = (array)$conditions;         if (isset($field) && isset($value)) {             if (strpos($field, '.') === false) {                 $field = $this->alias . '.' . $field;             }         } else {             $field = $this->alias . '.' . $this->primarykey;             $value = $this->id;         }          $query['conditions'] = array_merge($conditions, array($field . ' <' => $value));         $query['order'] = $field . ' desc';         $query['limit'] = 10;         $query['field'] = $field;         $query['value'] = $value;          return $query;     }        return $results; } 

see $query['limit'] = 10; field? limited 1 result, added 0 , chopped following code, builds prev , next array. don't know how gets 10 results, how sql query built, works!

it 1 has 1 bug: if make query , there isn't 10 results ahead of item search for, return random results.

it must because it's late, didn't understand trying do.

but anyway, since said find('neighbors') "quite close", i'll give option custom change fit needs. been said, if else less sleep deprived me , offers more efficient solution, take it.

anyway, solution: build custom find.
cake's docs explains how create one. that, find('lots-of-neighbors') find. creating new custom find seems pretty straightforward, not going explain that, should ask new question if don't understand there.

now, put in custom find function? well, copy find('neighbors') function , change need. i'll give link code, though don't have exact cakephp version, should double check.
understood, problem have function return 2 records, you'll have change limits inside conditions (line 3143, 3156, 3160).

that's in nutshell. if isn't want, i'll give go tomorrow morning.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -