kamikaze_pilot
kamikaze_pilot

Reputation: 14834

How to use zend paginate with normal sql query rather than zend_db_select

so basically you can use zend paginate via the following:

$sql = new Zend_Db_Select($db);
$sql->from(table);
$sql->where(zend_db_select_sucks = 1);

$paginator = Zend_Paginator::factory($sql);

is there a way to use paginator such that you can set $sql yourself without using zend_db_select

so just

$sql = "SELECT * FROM table WHERE zend_db_select_sucks = 1"

$paginator = Zend_Paginator::factory($sql);

?

Upvotes: 4

Views: 2194

Answers (2)

b_dubb
b_dubb

Reputation: 421

you have to wrap your SQL query string inside of query() before passing it to anything else otherwise ZF doesn't know what you're telling it

$db = new Application_Model_DbTable_Example(); // if you've created a model for your db
$select = $db->query("SELECT * FROM table WHERE value='varstring'")->fetchAll;

and then you can send that off to paginator

Upvotes: 0

Simon Lang
Simon Lang

Reputation: 42645

Isn't the point of the Paginator factory that you can also pass it a rowset and it will paginate that too? I just tried this out and it seemed to work for me (even though I usually use Zend_Db_Select)

$db = Zend_Db_Table::getDefaultAdapter();
$rowset = $db->query('SELECT * FROM user')->fetchAll();
$paginator = Zend_Paginator::factory($rowset);

Upvotes: 7

Related Questions