Dynamic Column Selection Menu and formula generator - php

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?

Related

Search large number of string php and mysql

I hope this is correct way to ask question.
I am doing some custom development in php(Magento) and I have one requirement to collect all the string from my files and save on my custom table. As of now I created one button(Kind of refresh to get all of the strings) this collect all of the string and save in my custom tables. When I clicked on first time then it found more then 15K string and save in my custom tables which is correct. But whenever I am trying to click on Refresh button I need to avoid duplicate the string in my custom table.
So my question is how can I avoid string comparison(I am using "avoid" word because this number might be increase it can be 20K in future) for each to avoid duplicate or can I add UNIQUE Constraint in my table ? Which one is correct way or any expert suggestion?
EDIT
I want to avoid duplicate entry in my table. For example, when I click on "Refresh" button at that It found the 5 entry and it save in my custom table,
table
id some_column
1 (Excl. Tax)
2 (Incl. Tax)
3 Target Rule/Product
4 File %1 does not exist
5 hello
...
now whenever I am clicking " Refresh" button at that I can find the same entry but I don't want to add this entry in table as it is duplicate.

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

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/

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?

Displaying dynamic text based on drop down box selection

I am using Dreamweaver to create a site.
I have created my database within phpMyAdmin and have two tables set up that contain the data I wish to display on my site. (it is a football team site and the page I am editing displays player profiles).
I have set up a drop down box, which is connected to my players table in phpMyAdmin. This I have set to display surname of the player. (I've set up the recordset to retrieve all data from my "players" table)
Below that, I have another div which contains text that I want to display based on the selection on the drop down list. For example, Position, appearances, goals, assists, etc.
Position: Dynamic text to be displayed here
Appearances: Dynamic text to be displayed here
etc
(This data would come from the "players_info" table - but the two tables are connected via the player_id field which is contained in both)
What I can't seem to do is work out how to get the text to update when the user would select a player from the drop down list.
Any help would be greatly appreciated.
Thanks
James
You can do these using ajax function.
when you select a player name ,then javascript or jquery event will be called which include a php file.
This php file must contain the sql which fetch your desired player information.
when server give response, then display it your corresponding div

Categories