views:

41

answers:

1

I have the following query:

$this->select()
 ->where("`name` LIKE ?",'%'.mysql_escape_string($name).'%')

Now I have the Zend_Paginator code:

        $paginator = new Zend_Paginator(
                // $d is an instance of Zend_Db_Select
                new Zend_Paginator_Adapter_DbSelect($d)
        );      

        $paginator->getAdapter()->setRowCount(200);

        $paginator->setItemCountPerPage(15)
                ->setPageRange(10)
                ->setCurrentPageNumber($pag);

        $this->view->data = $paginator;

As you see I'm passing the data to the view using $this->view->data = $paginator Before I didn't had $paginator->getAdapter()->setRowCount(200);I could determinate If I have any data or not, what I mean with data, if the query has some results, so If the query has some results I show the to the user, if not, I need to show them a message(No results!)

But in this moment I don't know how can I determinate this, since count($paginator) doesn't work anymore because of $paginator->getAdapter()->setRowCount(200);and I'm using this because it taks about 7 sec for Zend_Paginator to count the page numbers.

So how can I find If my query has any results?

A: 

Why would you setRowCount() to a magic number? If whatever method Z_P is using to discover the total number of rows is taking a long time, you might want to override it that way, but you'd want to compute the actual value, wouldn't you?

In most cases, Z_P ought to automatically get the right number (internally, via a subquery). If that subquery is taking too long, you can try building your own Zend_Db_Select to perform the count, and pass that to setRowCount().

timdev
Yeah thats the main problem actually, setRowCount(), but as you can see here http://tinypic.com/r/vesy9c/6 the count query takes a lot of time, the table is also really big, million of rows, can you help me to write a better count query..or what should I do?
Uffo
If I see it correctly, that's 0.00007 seconds, not 7 seconds (7*10^(-5)). on that picture all the 3 queries together take 2.7 seconds.
robertbasic
Those are 7 seconds, I have just tested it again :)
Uffo
You're going to have to optimize your database. I don't know enough about fulltext indexing in mySQL, but you might want to investigate. The root problem here is that you're using LIKE with a leading % on the right-hand side, which means your poor DB has to scan every record looking for matches.
timdev