yii2 dataprovider get all filtered data - php

I have grid view of student table when I filter table, for that instant I can get filter data by giving following
$allData=$dataProvider->getModels();
This $allData contains filtered data.
If I have 50 records, when I filter them I get 30 records, but this $allData shows only 20 records due to pagination limit 20.
so How do I get all my 30 filtered records into a variable as well as pagination?
if I set pagination size =0, then I will get all data, but I want pagination too.
So, how do I solve this?

If youre using DataProvider, you have $query as well. So using:
$models = $query->all();
will return all filtered models, and DataProvider will still have pagination.

Related

Group By and pagination not working togather laravel

$campaigns = Campaign::orderBy('id','DESC')->paginate(2)->groupBy('offer_id');
results returning 2 rows but no pagination links.
You should use groupBy first then paginate in Laravel as its chaining of method calling your last method will be given result as two records without pagination
Campaign::orderBy('id','DESC')->groupBy('offer_id')->paginate(2);

Codeigniter mysql db query to display 3 rows of results on page using 2 tables on 3 joins

New to codeigniter and having trouble on a query for 2 tables. The first table "claims" is loaded into a page showing 3 of the 15 or so cells in the headings (as per claims.png), a method in the second method is then called to load site/claims/view_claim_det/$claim_id when user clicks the "view claim" link. which the new view by claim_id.
The second table driver_detail has to load 2 rows (#1 is nonfault and #2 is atfault info ) through a query defined by nonfault claims.claim_driver_id1 = driver_detail.driver_id and atfault claims.claim_driver_id2 = driver_detail.driver_id (2 rows returned to display as per ClaimsDetail.png).
I have the claims table row loaded where the results fall mainly at the end of the page, I can't figure how to call the driver_detail table and run the 2 queries to then display the results required for each Nonfault and Atfault info.
I'm sure its something so easy, each time I think I have it I get plagued by php errors.
Any help would be amazing!!
claims view
claims_detail view
There are two things you can do in this case.
Create 2 methods, one for each view: atfault and nonfault that would return their own sections individually. Then..
1,. You could use Ajax to display each sections separately.
2, if you need to provide an initial view then you could call these methods within your main method and pass the rendered sections as a variable to your view.

Wrong pagination link count laravel

I need to skip the first n records, say 5 from a table and paginate the rest of it. The following is the code that i am using.
$skipNewsListArr = array(1,2,3,4,5);
$wrongPaginationLinks = DB::table('news')
->whereNotIn('news_id',$skipNewsListArr)
->orderBy('news_date','desc')
->paginate(5);
But the above code outputs the pagination links corresponding to the whole table. How can i achieve pagination by skipping records based on some condition.

PDO/Mysql PHP Recursive category Tree with showing all items

Afternoon,
I am using a recursive function to get a list of items from a data table. But if the results are more than 2000 it seems to make 'mysql go away'.
I have split the database into 3 tables :
menu = category_id,category,parent_id
item_categories = item_id,category_id
item_info = item_id,price etc..
All the _ids are integers only.
The issue I have is there is 7000 categories at present with sub-levels up to 7 deep.
There are around 80000 items at present which can be in multiple categories.
The database is for quite-specific boiler spares department.
When a category is chosen I would like to count all items in the category and all of their sub categories as well as sort them by price. I need to get a total count for pagination, but i only wish to display about 50 results per page which i sort either by price ASC or price DESC depending on client choice.
To try to allow the page load to look nice and give it a little extra time I am loading the page then once loaded it calls the itemview page via jquery, with a loader on screen until results are returned. When 'mysql goes away' the loader just stays on screen..
I am using PDO with mysql, with PHP.
I have the ids indexed in all 3 data tables.
any guidance would be appreciated..

PHP & MySQL Join

I'm relatively new to coding in general, first year CS student and all of that. I'm using PHP to display a list of school classes categories and a list of assignment posts within each category. The desired output would be something like this:
CATEGORY 1
-Assign Post 1
-Assign Post 2
CATEGORY 2
-Assign Post 0
Using join gives me partial functionality, because it gets all the assign posts, but when I loop through and post the data it posts the Category title more than once. I then tried using group_by but it's only posting one post per category.
I'm not gonna post all my code, simply the db queries. I'll happily post the other code if you think the problem may be there.
//Select our classes, and get assignments from each class
$this->db->select('*');
$this->db->from('categories');
$this->db->join('assignments', 'categories.cat_id = assignments.assign_cat_id');
$this->db->group_by("cat_id");
//Return the classes and assignments in an array
$query = $this->db->get();
return $query->result_array();
Not to tricky right? Any help is of course appreciated :).
UPDATE
I have figured out that group_concat will post the assignment names, and then I can explode the results. Is this the only way, or is there a way to get it to post in a nice friendly array. The only reason I ask is I feel this adds un-necessary code in my view file, where I'm exploding the data.
Thank you!
Dont use group by ...use sort by Category id and while showing/or preparing array of data you can club records as per category..you cant achive this by single SQL

Categories