This topic is locked

Button to search matching data

8/12/2019 10:54:13 PM
PHPRunner Tips and Tricks
D
david22585 author

Lets say that you have a page where you want to search the table with any data that matches. Lets say for example that your table keeps the inventory level of a product and you want to view the history of that inventory over time with a button on that products view page. Table A is what shows the product and current inventory, and table B is for the history of the inventory. Lets say that the product ID is 27837. When you update the inventory in table A, it will read the last inventory of product 27837 in table B, and add a new row with the new inventory.
Now lets say that your on the table A view page of the product and you want a button to search table B for the inventory history. I will start with the SQL designer for Table A and create an alias line called:

inventory_history.productid as producthistory,


On the fields page, have this field only appear on the View page. On the designer page, delete the label for the field producthistory. Click View As/Edit As, and View As Custom. Use this code to match and make the field appear as a button with a link:

$value = "<a href=\"InventoryHistory_list.php?q=(productid~equals~".$data["productid"].")\" class=\"btn btn-default\" role=\"button\">View Inventory History</a>";


Where it says btn-default, that makes it part of the CSS bootstrap buttons. This will work with all the themes for what button view you want. You can use the following:

btn

btn-default

btn-primary

btn-success

btn-info

btn-warning

btn-danger

btn-link


https://www.w3schools.com/bootstrap/bootstrap_buttons.asp
This shows the bootstrap styles for comparison.
This is very similar to Example 6 on https://xlinesoft.com/phprunner/docs/inserting_button.htm, but what this does is allows text after the data value which is needed for a search. If you want it to search for different data, just change the search string to the value that you need:



(productid~contains~".$data["productid"].")

(productid~startswith~".$data["productid"].")

(productid~endswith~".$data["productid"].")

(productid~morethan~".$data["productid"].")

(productid~lessthan~".$data["productid"].")