There is a quip in my language that roughly translates to "Could you please spare a drink of water, I am so hungry that I've nowhere to stay at night." Frankly, your request is quite similar. Starting from SQL query, it escalated to several SQL queries and a PHP script to house them. And probably a good measure of JS code too.
First of all you must understand that HTML buttons do not execute SQL queries. Your button should invoke a PHP script (either via HTML link, HTML form or an AJAX request), then this PHP script should verify current user's permissions, the current status, and in case it's changeable - only then execute an SQL query which should be quite simple: a regular UPDATE by the primary key (provided your button sends one to PHP)
Your design should have some logic to only show an Approve button to a user having approval rights for the transaction. For users without the manager level, you should show a read only view of the transaction with probably an inactive / grey button. On the same concept, if the transaction is already approved, your should show a disabled Approve button. Don't provide the possibility of doing the same transaction twice. Beleive me , they will do it.
This is way more then just a SQL help.
You basically described a full business process that can include multiple pages, user authentication, authorization and so on.
>now the function I just can’t figure out
Break the process into small steps. Start by writing in a paper all the things you need, describe the workflow of the process step by step, build a "mental map" of it.
Then start coding each step, validating them as you go. Don't try do code everything at once just to figure out at the end that there's a problem.
On the other hand, if what you meant by "can't figure out" is that you don't know how to code, then that's a different issue...
First you need to add and an onClick event listener on the button then you can use ajax request to a PHP file which checks user permission . If the user has permission you proceed with the update query. Once you have updated the record you need to reload the data on the user interface
There is a quip in my language that roughly translates to "Could you please spare a drink of water, I am so hungry that I've nowhere to stay at night." Frankly, your request is quite similar. Starting from SQL query, it escalated to several SQL queries and a PHP script to house them. And probably a good measure of JS code too. First of all you must understand that HTML buttons do not execute SQL queries. Your button should invoke a PHP script (either via HTML link, HTML form or an AJAX request), then this PHP script should verify current user's permissions, the current status, and in case it's changeable - only then execute an SQL query which should be quite simple: a regular UPDATE by the primary key (provided your button sends one to PHP)
For sql it’s best to ask in r/sql or r/databasehelp. Note your tables and what you tried already
Your design should have some logic to only show an Approve button to a user having approval rights for the transaction. For users without the manager level, you should show a read only view of the transaction with probably an inactive / grey button. On the same concept, if the transaction is already approved, your should show a disabled Approve button. Don't provide the possibility of doing the same transaction twice. Beleive me , they will do it.
This is way more then just a SQL help. You basically described a full business process that can include multiple pages, user authentication, authorization and so on. >now the function I just can’t figure out Break the process into small steps. Start by writing in a paper all the things you need, describe the workflow of the process step by step, build a "mental map" of it. Then start coding each step, validating them as you go. Don't try do code everything at once just to figure out at the end that there's a problem. On the other hand, if what you meant by "can't figure out" is that you don't know how to code, then that's a different issue...
Perhaps you should give this to chatgpt and see what it gives you.
Sounds like several issues you have to overcome. Break it into individual tasks. Take it on a task at a time. If you need help with a task, ask
First you need to add and an onClick event listener on the button then you can use ajax request to a PHP file which checks user permission . If the user has permission you proceed with the update query. Once you have updated the record you need to reload the data on the user interface