on click link (More) Show more table field data ..?? - php

There is large number of column in my database. I fetch all this on my webpage.enter image description here Is that any way to show 4 to 5 column with MORE link. On click remaining wiil be display on the same page same table raw wise

Ajax is the best solution for it. Or You can do that by jQuery hide() and show() function. Hide all after 4/5 column and append a button which will show rest of the column when clicked.
check it - https://jsfiddle.net/iqbalbary/sjnybu05/

Related

PHP - Switch case & _GET and Dynamic URL creation

What I have in my index page:
if(isset($_GET['d']) && $_GET['d']!="" ){
switch ($_GET['d']) {
case 'singlerequests':
ViewSingleRequests();
break;
}
I have a sidebar menu in which I call cases like index.php?d=singlerequests, this saves me from creating a new php file every link i want to have in the file.
What I want to do:
I created a page, in which I am listing multiple rows of date. My data row has multiple columns so instead of showing all data with all columns on that page, I will only have a summary table and a "View More" link next to each row, in which they view the full data on another page. (something like below)
Row Name | View More Link
Row Name | View More Link
Row Name | View More Link
I can retrieve the unique ID for that row in my code but i dont know how I can pass that data(identifier) through above switch case to another function, where i will display all columns of that row to user? If it's not possible that way, how can i do it in a different way?
Thanks.

Dynamic Column Selection Menu and formula generator

How to create a dynamic menu in php html page wherein user can do all of following from front end:
I want that to create a two column window that displays different db col names from different tables. First window shows options for selection while, second window shows options selected and arthimetic operations on them from front end. We can save and create the output of these operations over selected columns into a new table or column of output. We can reuse this formula every time..since we have saved it by simply pulling the result col and echo it on a page.
Example: user selects a database column (e.g. "net profit") from first window and by clicking simply moves into 2nd window. Next he click "subtract button" and a minus sign appear in front of "netprofit" in 2nd window and then selects "tax" from first window and moves it to 2nd window. Next he clicks "divide button with / sign on it" and then clicks "total assets" from first window . Next he clicks save and winow prompts to assign a name to out put of the above..user names it as average profit over assets and saves it into new table. The output in table therefore will be processed based on this custom formula creation window and we can create complex formulas and save thier output and extract as required. The formula we created in above example is as under:
(Net profit before tax- tax)/total assets = Average net profit over assets.
Please guide on highlevel, how i can accomplish this . Also.tell me if there is an Api that can help achieve this quickly or I need to do all coding from scratch.
I believe one solution is to implement the window using checkbox list for colums pulled from db and embed them in scroll down div.
Next for all selections made take them and echo in a formula feild. For each add or subtract or multiply or divide button ..take respective values i.e + , - , × , ÷ and echo them in respective field. Once the formula is constructed .. post it and store in a new variable $ result. Next use it in a function or simply save/ insert it into a new table called formulas. Next extract values from the table and display/ echo on screen.
Any suggestions??? Am i thinking correctly?

How to define when you should hide "Show More" button?

I have a mysql table of products.
I have a product listing page where User has a button "Show more" to load more products on the page.
After clicking on this button jQuery calculates how many displayed products are on the page (N) and makes an AJAX request to the table for getting 20 more products (N+20).
Now I should create a trigger when I should hide the button.
Which trigger I should choose? What is the best way to define that there are no products.
Please, help.
I have no idea how have you reached that functionality since you are not sharing the code and thus I cannot give you the most accurate help, only this one:
when loading the page and retrieving the first X rows from DB, retrieve the amount of all rows (matching the search criteria) as well
make this count visible to the template
in jQuery, count how many rows have you already loaded
this means, that on page start you are displaying X rows, the amount of total rows is Y, and the number of currently displayed rows is Z
immediately after the page is loaded you need to compare if Z <= Y then do not display button else display the button
if the button was displayed I guess you are listening to click event on this button and then performing your AJAX request, here after the AJAX is successfully completed, you need to do Z += X and again compare if Z > Y then hide the button
That should be your logic, now turn it into your code.
There are 2 ways I guess,
The simple way would be counting number of response rows that's returned by your AJAX function. If it's smaller than 20 then hide the button.. However, if your records number is a multiple of 20 then there will be a glitch in the last response, because it won't hide the button.
The perfect way is to calculate number of records in your table, then save that data in your js variable. Then compare that variable value with the number of times you ask for another record.. If they have same value then hide the button, if not then show the button.
It depends on the frequency of product list updating.
If the amount of products changes often (say, more than once a day or so), I would execute a query on each AJAX request, checking if I have more items (for example, checking if N+20 >= count(id) of products), and on the callback hide the button.
Otherwise, I would just inject the amount of products as a JS parameter into the page, validate against it on each click (N+20 <= count_products), and save myself some AJAX \ SQL loading time.
you can get the count of all lines using PHP and save it in an hidden field or in a variable after that you can test (using jquery) to see the current number of records in the page (you are already doing that ) then test it with the number in the hidden field/variable and show/hide your button
Finally I choose next variant:
I want to load more 20 products.
In backend code I switch this number to 21.
So then in jQuery I show just 20 BUT I check if there one more product I should NOT hide the button.
That's it.
Thanks guys anyway!

Adding and removing rows on a CGridView Yii

I have a search form that the user uses to find persons from the database, the results are displayed on a table, then the user can choose persons from the results table and add them or remove them from another table (the CGridView) and this last table will be saved to the database when the user clicks save button. My problem is that I'm adding and removing the persons (the rows) with jQuery, so when I use the sort function of the CGridView, clicking any header, the rows that were added with jQuery are lost. Also, when I remove rows from the last table I want to refresh the table so the zebra style rearranges. How can I do this without losing the data added with jQuery?

Yii CGridView bulk edit/update?

I want to edit/update, multiple rows together in Yii CGridView.
Say, each row has a checkbox and a single edit/update button, I select multiple rows and by clicking on edit/update button all selected rows are opened for editing and update.
Is this possible with Yii CGridView..??
Use the selectableRows property of the CGridView.
According to Yii Documentation for CGridView
public integer $selectableRows;
the number of table body rows that can be selected. If 0, it means rows cannot be selected. If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected. A selected row will have a CSS class named 'selected'.
You can use the the $.fn.yiiGridView.getSelection(containerID) to retrieve the key values of the selected rows.
Add some more buttons either at the top or bottom of the gridview with actions for edit, delete or whatever action you need to take and pass the key values retrieved above.
If you want to edit rows in-line you can use extension phaActiveColumn which I messed up to support multiple rows (the whole table if desired).
EDIT: well, the extension basically creates an input field replacing the grid cell when user clicks on the cell. The field will have the cell's value for starters and it then sends an ajax call to controller, as soon as the user presses enter, asking to save the value of the field, which will be the user's input.
My addition was to create one such field for every cell in the row and store user input in javascript objects which then get send all at once with one ajax call to the controller. Multiple row updates are supported (creating adequate number of javascript objetcs).
If anyone has any interest in this there it is.
phaEditColumn2
phaAbsActiveColumn2

Categories