I'm a beginner to zend framework...until now i was doing pagination by fetching all details from DB..my friend says that it is not a good way for pagination....
he give me the following reference from Zend site...now i have some doubts...
1.what is setRowCount?is it a field in the table?
2.what is item_counts and RowCount?
my DB name is sreejith.
my table name is employee.
the code is:
$adapter = new Zend_Paginator_Adapter_DbSelect($db->select()->from('posts'));
$adapter->setRowCount(
$db->select()
->from(
'item_counts', array(Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'post_count')
)
);
$paginator = new Zend_Paginator($adapter);
OP code pasted from:
http://framework.zend.com/manual/1.12/en/zend.paginator.usage.html
That example is showing the ability to optimize how the total number of rows is calculated (needed to perform pagination, well to render the UI navigation at least).
As it says, "For example, if you keep track of the count of blog posts in a separate table, you could achieve a faster count query with the following setup:".
Look at the more simple examples passing a Zend_Db_Select to the factory... like: Zend_Paginator::factory() - That will probably be all you'll need.
Related
I am working on a pimcore project (version 4.4.3) but still pretty new to pimcore itself.
First I made an Object called 'Event' in the admin panel and added a data component -> relation -> Object called 'speakers'.
Now I have a controllerAction which needs to return these speakers, but I don't want them all at once so I wish to add a limit and offset.
The result of $eventClass->getSpeakers() returns an array with objects on which I don't seem to be able to put any filters.
Of course I can filter them after I retrieved all of them, but if possible I would like to filter them in my request.
So my question is, how do I filter the related objects on my object?
I'm afraid that currently you can do it only using SQL. It will look something like this:
SELECT dest_id FROM object_relations_5 where fieldname = 'speakers' and src_id = 123 LIMIT 10;
Where 5 should be your class' id and 123 your object's id. You can join other tables to do more filtering, but it's getting complicated.
Commonly if you have to write custom SQL code, something is wrong with your data model. Maybe your "speaker" class should have a single href relation to "event" - this way you could get speakers listing easily with all filtering you want.
You can use the Listing object for that
$speakerId = 123;
$list = new \Pimcore\Model\Object\Event\Listing();
$list->setCondition("speakers like '%,".$speakerId.",%'");
But you can only filters the speakers with their IDs only. If you want to filter them with some other attributes then you have to make a join with object_relations_ClassID table.
Also have a look at the following link
https://pimcore.com/docs/4.6.x/Development_Documentation/Objects/Object_Classes/Data_Types/Relation_Types.html#page_Filtering-for-relations-via-PHP-api
I have a custom table that I created named cars_plugin and it has columns id, name, color, model
Now, I can get list of cars using
$sql = "SELECT note FROM cars_plugin WHERE ID = '$id'";
$query = $wpdb->get_results($sql, ARRAY_A);
foreach($query as $car){
// list cars here
}
The above code works as planned, and I could create a pagination for that, although it will be difficult, now my question is, if I have a custom table like that how do I query the table so I can be able to use the built-in Wordpress pagination functions?
This can't be done I think
I found no way to use WordPress default pagination for custom table. Cause the default pagination is initiated in WP_Query class which is curated or built or written only for querying posts from {wp-table-prefix}_posts table and may be joining other table related to posts.
So what is the solution ???
May be you can create your own class which will return you the result with pagination and this could be by extending WP_Query class. But this method will need a lot of modifications to manipulate the base class default methods. So I would prefer writing a separate new class for this than extending the WP_Query.
Another way would be straight PHP method. You can chunk the queried result and show them page by page. And I think it would be the easiest and smart way to do pagination for custom table in WordPress. For finding more on this method you can check those below links-
https://wordpress.stackexchange.com/questions/53194/wordpress-paginate-wpdb-get-results
http://www.walkswithme.net/wordpress-pagination-for-custom-tables
Hope that helps.
i'm new to laravel and i downloaded a starter site here,
https://github.com/mrakodol/Laravel-5-Bootstrap-3-Starter-Site
The site save language in table includes id, lang_code (e.g en), and the article database has a column "language_id" which seems to be used for filtering by language. But in the homecontroller, i see this line:
$articles = Article::with('author')->orderBy('position', 'DESC')->orderBy('created_at', 'DESC')->limit(4)->get();
This line select all the articles and print it out without language filter. How can i select article only in current language?
You can use where for filtering columns. It of course depends on what kind of id's given for languages. You need to check db.
$articles = Article::with('author')->where('language_id',1)->orderBy('position', 'DESC')->orderBy('created_at', 'DESC')->limit(4)->get();
I'm relatively new to Yii and would like to experiment a little. I have looked around all over the internet and I have absolutely no idea how to approach this. I have mastered the basics of Yii but I think that this is quite advanced or I'm just being stupid.
I have a MYSQL table with a list of items bought. This table has CUSTOMER_ID as the main field with each CUSTOMER_ID possibly having more than one ITEM's. I would like to do a count BY TRANSACTION_ID and then assess as in line with the following logic:
1) IF myCount = 1 then businessType = 'New';
2) If myCount = 2 then businessType = 'Repeat';
3) If myCount > 2 then businessType = '2+ Repeat';
I'm not sure where and how would be the best way to do this however? afterSave()?? Or in the controller? I have to get the result of the query into a GROUPED CActiveDataProvider object as I feed this data into Highcharts.
My grouping needs to look as follows (From lowest level to highest) :
businessType->store->item->{Count(ITEM), SUM(Cost)}
I am unfortunately not able to add a variable to the table and would really like to achieve this without having to. Any help appreciated!
to do this you will need to use CDbCriteria to group results in a CActiveDataProvider. See here http://www.yiiframework.com/doc/api/1.1/CDbCriteria#group-detail. You'll need to implement it in your controller something like this;
$criteria = new CDbCriteria;
$criteria->select = 'the columns to select, and maybe SUM()';
$criteria->group = 'columns to group by';
etc
etc
$dataProvider = new CActiveDataProvider('model name', $criteria);
Without knowing the exact implementation of your database I can only give a general example, but you should find something like this works for you. I'm not sure how to get the grouping your talking about as businessType->store->item->{Count(ITEM), SUM(Cost)}, as you haven't shown your database and model structure.
This isn't entirely exclusive to cakephp but that's the framework im using so any help by thateans would be great..!
I have a MySQL table of posts, tags and post_tags to associate the two together.
I've set up my full text fields on my posts table to be the body and title but I wanted to include the associated tags into my searching too and order the posts based on where the search query mathes any of the tags assigned to the posts.
Would I need to build a hefty SQL query for this perhaps? Also if anyone could offer a cakephp specific solution I'd also like to cache the searches too using the inbuilt cache methods...
Many thanks!
Use the "find" function in CakePHP:
$result = $this->Post->find('all', array('conditions' => array('Post.body LIKE' => '%search_text%')));
If you want more information from a query put this line before "find" function:
$this->Post->recursive = 2; //or 1
In $result you should get all tags which belongs to the founded Posts.