Catalog View with pagination (Codeigniter) - php

I need to build a catalog with posts that I get with a query, each page of the catalog will have 27 spots for posts (except for the last page). The problem is that some posts need two spots if there was an image attached when the post was created. I don't have a field in the database that tells me if the post have an image or not, I would add it if is necessary. So far I have this two possible solutions:
1) Get the 27 results and then loop trough them to see how many posts have images and then calculate an offset of the posts that where not displayed so the other page would start with the correct number.
2) Add a field in the database for tracking if a post has an image attached and then run a query with a conditional so I get only the posts I need to get the 27 spots filled.
The problem that I'm having is on how to keep track of these offsets. What happens if the user wants to go to the last page? Do I need to query all the posts and then calculate the offset for that last page?
I'm hoping I'm making some sense, sorry for my english too, I'm not a native english speaker.
Thanks in advance.

You can join both the tables if results are correct and convinent as expected by you and secondly in codeigniter you don't have to worry about the pagination stuff for last and first, the pagination library takes cares for that. For more details on pagination library, visit the below link:
http://ellislab.com/codeigniter/user-guide/libraries/pagination.html

Related

Conditional Calculations for field entries within Wordpress using PHP

I was wondering if anyone with some experience with PHP could help. I've been trying to figure out if there is a way within WordPress (GravityView) to make calculations based on certain entries within a form and then use conditional logic to display different images dependent on the result from this calculation.
In this case, I am trying to display different images relating to different measures of a client, i.e. their value to our company, their engagement with our company. Taking the example of Satisfaction I have added a field to one of our forms where if a request is completed unsuccessfully with them it will count that entry. However, I then need to sum all these unsuccessful entries so I can relate them to the different levels of satisfaction (the images). i.e if there are 10 unsuccessful entries for a given client they will be given a poor level of satisfaction and if there are 0 they would be given an excellent level of satisfaction. This is not possible to do within a view in gravity view as you cannot use a shortcode within a shortcode. I cannot sum all the entries using [gvmath] for a specific field and then use [gvlogic] to assign the different levels to different images. So I was wondering if there is a way to bypass this by issue by writing the code directly in PHP.
Also, another issue is within the form that is used for the requests there is a field where the member ID is inserted. Each of our individual clients is given a specific member ID and then a page is created for that client where their 'Levels' are displayed. So ideally the PHP code would be able to sum the entries for only that specific member ID and then using the result of that calculation assigns a particular image to it depending on the answer. Is this all getting too complicated and not able to be performed within WordPress? I've been trying to wrap my head around it all week so any help would be greatly appreciated.
I've attached a picture of the specific images that I would like to assign to the different levels.
Let me know if any further context to my issue is required.
Thanks :)
Levels

How to link/navigate through SQL search results in PHP one page at a time

I am building an admin type script to view records within a mySQL database. This links in numerous tables and is all working perfect. I have now added a filter form to allow me to search/filter for records that match specific criteria. Again this works perfect.
The problem I cannot get my head around is this...
For each record I have a link that allows me to go into that record and view more information/perform tasks on the record.
Initially it was simple to have a 'Previous' and 'Next' link for cycling through the records which meant I didnt need to go Back to the search results to go to the previous/next record. It simply +1 or -1 from the current record ID to generate the link.
Now however I am filtering so the records ID's might be 1,3,4,5,8,10,15,30 etc
The problem is now that once I click into any one of the results to view that record I essentially lose the filtering and all of the results.
The only way I can think of achieving this is to pass the filter variables in with the link and redo the filtering every time the View page is loaded, working out where the current record is in the result set and creating a link based on the previous and next records in the result set.
Am I doing this correct or is there a better way?
I have searched but most answers are geared towards the basics of looping through mySQL query results which sounds the same but is very different.
Any advice would be greatlt appreciated!

Laravel view more link pass id

Hello I am using laravel 5 to display a 20 column csv from my database, I have a foreach loop displaying 5 of the 20 columns in a table and then a view more button to take you to another page with a table showing all the information of that particular row depending on the id.
My question is how do I pass the id to the other page so I can do another foreach loop to display the rest of the info? I have it so when you hover over the link it's display the id. I know this is vague so if you could point me in the right direction it would be much appreciated as I'm not home at the minute so I can't post my code, thanks!
What you are looking for is called pagination and lucky for you Laravel has made a beautiful function to make this easier documented at https://laravel.com/docs/5.4/pagination.

codeigniter search box and keeping data

I want to keep page in search form and when I visit another page and return to previous to see only what I search.
For example, I have page with table, in that table I have list of all products which is 30 products. When I submit search query for some word and get per instance 5 products, I want to keep that and visit all another pages and when I back on product page to see again only that 5 products.
Any help?
You're looking for a way to store dynamic data. Your best bet would be to use something like Sessions or LocalStorage

Display column-based instead of Row-Based records in PHPMaker 10

I'm having trouble and I wanna ask, if it's possible to have column-based tables when PHPMaker generates tables for records? Because when I generate it only generates row-based records. Copy-paste the link below to URL to understand. I'm sorry I'm not knowledgeable in PHP that much. It's just very easy to make a complete application with this program and the only thing stopping me is the format of how it's shown. An example of how I wanted it to look like would be this one
I hope somebody answers! Thanking you all in advance!
That kind of column based view is not suggested as it has many flaws when we try to display huge number of records. Adding pagination or sorting feature is very difficult and not user friendly.
As you have so many fields you could try to group them into tabs by relevancy. Once you put them under different tabs they can be easily navigated and easily fit into row based structure.
Creating tabs is PHPMaker is very easy, on field configurations screen you will get Page No config next to each field. By default it set to 1 you can set required page number as per your choice. Once you done go to Table config of the table which is second tab available for each table. Scroll down to bottom and and click on 3 dots next to Page Labels config (Under Multi Page Config). This will pop up a screen where you can add captions for your tab.

Categories