+ Reply to Thread
Results 1 to 9 of 9

Thread: Problem Zend_Paginator (dynamic select in the query)

  1. #1
    mido is offline Junior Member
    Join Date
    Jan 2009
    Posts
    4

    Default Problem Zend_Paginator (dynamic select in the query)

    Hi,


    Well, I have a question, If my select is dynamic, posted from form to the Action controller where I set within the Zend_Paginator, so how to set a pagination in this case, i need to know how I post again the parameter of my first post with pagination link ?

    is there any one how implement Zend_Paginator this case ?

    thankx!

  2. #2
    mido is offline Junior Member
    Join Date
    Jan 2009
    Posts
    4

    Exclamation figure out the problem

    this my action , my problem when i click in link pages of paginator (for exemple 2 or 3), i have a problem with $value because my $value is posted the first time in search form from another page. (my select must be dynamic)

    if any one find solutions, thanks

    function xxxAction {

    $value = this->_request->getPost('param');

    $selection="SELECT *
    FROM table
    WHERE field1=$value";

    $db=Zend_Db_Table::getDefaultAdapter();

    $your_db_results = $db->fetchAll($selection);


    $paginator = Zend_Paginator::factory($your_db_results);
    $paginator->setItemCountPerPage($pageNumber);
    $paginator->getItemsByPage($itemNumber);
    $paginator->setCurrentPageNumber($this->_getParam('page'));
    Zend_Paginator::setDefaultScrollingStyle('Sliding' );


    //this are your results from db
    $this->view->your_db_results = $paginator;

    //this is paginator
    $this->view->paginator = $paginator;

    }

  3. #3
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    You could probably store the $value in a cookie or session on the first request and use that value on subsequent requests.
    Brenton Alker
    PHP Developer - Brisbane, Australia

    blog.tekerson.com | twitter.com/tekerson | brenton.mp

  4. #4
    Untitled No. 4 is offline Junior Member
    Join Date
    Jul 2008
    Posts
    28

    Default How about something like this:

    $value = this->_request->getPost('param');

    // Start a session
    $session = new Zend_Session_Namespace('value');

    // If $value is set then you are on the first page and so you store $value to
    // the session
    if ($value) {
    $session->value = $value;
    }

    // put $session->value into your query
    $selection="SELECT *
    FROM table
    WHERE field1= " . $session->value;

    $db=Zend_Db_Table::getDefaultAdapter();


    // You don't need all your results at once but only the results for the current
    // page, so instead of getting all of them just get let the paginator get you
    // the ones you need

    // Delete following line
    //$your_db_results = $db->fetchAll($selection);

    // and instead put your query into the paginator
    $paginator = Zend_Paginator::factory($selection);
    $paginator->setItemCountPerPage($pageNumber);
    $paginator->getItemsByPage($itemNumber);
    $paginator->setCurrentPageNumber($this->_getParam('page'));
    Zend_Paginator::setDefaultScrollingStyle('Sliding' );
    ------------------

    Putting the session into the query should work but I'm not sure about using the paginator on the select query like that as I've never built my queries like that. I would use the db factory instead, so it would look like that:

    $value = this->_request->getPost('param');

    // Start a session
    $session = new Zend$value = this->_request->getPost('param');

    // Save this into your registry in the bootstrap and then you can fetch it
    // again later, much easier
    $db = Zend_Db::factory('Pdo_Mysql', array(
    'host' => '127.0.0.1',
    'username' => 'webuser',
    'password' => 'xxxxxxxx',
    'dbname' => 'test'
    ));

    $select = $db->select();
    $select->from('table name', '*');
    $select->where('field 1 = ?', $session->value);

    $paginator = Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage($pageNumber);
    $paginator->getItemsByPage($itemNumber);
    $paginator->setCurrentPageNumber($this->_getParam('page'));
    Zend_Paginator::setDefaultScrollingStyle('Sliding' );



    Hope this helps...

  5. #5
    Untitled No. 4 is offline Junior Member
    Join Date
    Jul 2008
    Posts
    28

    Default How about something like this:

    double post

  6. #6
    mido is offline Junior Member
    Join Date
    Jan 2009
    Posts
    4

    Default test it with session nd it works

    thank you Untitled No. 4 .


    I test it with session, nd it works, but relating to performance i dont know...
    in java we have the term scope for the servlet request, session.... i dont know in PHP if we have this possibility with controller til define it.

  7. #7
    Eugen is offline Senior Member
    Join Date
    Sep 2008
    Location
    Croatia
    Posts
    400

    Default

    and why arnt you passing that param over get?

  8. #8
    mido is offline Junior Member
    Join Date
    Jan 2009
    Posts
    4

    Default to pass value it the get

    to pass it in get, i need to post it every time, well i can do that
    but the problem to add with url in pagination.html (the footer) i cant call for myvalue for exemple ($this->myvalue) , this is not the same view.

    pagination.html this is not my view , this an code that handle the paginator like

    helper.


    I dont know i you understand me ?

  9. #9
    mona is offline Junior Member
    Join Date
    Feb 2010
    Posts
    1

    Default problem using the zend_pagination

    hi all i'm new in using the zend_paginator and i wanted to make a selection from more than one table in same pagination so i made an array containing the result from first and second selection which contains different fields so i added a key for each and passed it to the factory of zend_paginator but the pagination didn't work so please can any one help in my problem thx

+ Reply to Thread

Similar Threads

  1. Dynamic select boxes with Zend_Form and JQuery
    By topcatxx in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 10-30-2009, 01:22 PM
  2. Zend_Paginator using Select Adapter
    By warden in forum Core Infrastructure
    Replies: 5
    Last Post: 06-05-2009, 05:01 PM
  3. select query using and,or
    By ganesh in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 03-16-2009, 04:04 AM
  4. select query
    By ganesh in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 03-03-2009, 12:33 PM
  5. Problem with Zend_db query select
    By krego in forum Databases
    Replies: 1
    Last Post: 12-24-2008, 09:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts