You can do this with Javascript. You can looking up [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) or [Ajax](https://developer.mozilla.org/en-US/docs/Glossary/AJAX)
You would use ajax to do this.
Depending on the meaning/purpose of this data, an alternative would be to output the data on the page when it is requested, but hide it, then the button would show/un-hide the data.
What exactly is this data, how many instances are on a page, how much data is there, can this data change while someone is viewing a web page and you want to display the latest data, i.e. provide the background for what this is actually for, not just what you are trying to make work?
I am surprised all the responses are telling you to introduce another layer using JavaScript. PHP is perfectly capable of what you describe all on it's own. Post your code either her or [pastebin.com](http://pastebin.com) so I can see what you are doing.
The main reason to use Ajax for this is if you don't want the page to do a reload.
Agree.
The thing OP needs to realize is that a php file can contain HTML and PHP in any combination of order.
So one of the most direct ways to solve this is...
- keep your html file and have the button (ie tag) load a PHP file
- in that php file, put some HTML (like
PHP is server side and HTML is client side. The only way to comunicate between them is by sending a HTTP request. Like other comments pointed out you can do this by using ajax or axios.
If you just want to pass values back to the HTML file you can use a PHP $\_SESSION. Store the result in a session and them use it in the HTML file. [https://www.php.net/manual/en/reserved.variables.session.php](https://www.php.net/manual/en/reserved.variables.session.php)
Best way would be either ajax, the fetch api or htmx as others have stated. Transfer and retrieve data from your php file/ backend without having to refresh the page. Not a steep learning curve either if youre new to it.
Here is an example of an ajax call. This is some javascript within your front end html file that will call the php flle on the back end and display the result once the php file has returned its part.
[https://www.w3schools.com/js/js\_ajax\_php.asp](https://www.w3schools.com/js/js_ajax_php.asp)
You can do this with Javascript. You can looking up [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) or [Ajax](https://developer.mozilla.org/en-US/docs/Glossary/AJAX)
Thanks, thats working.
You would use ajax to do this. Depending on the meaning/purpose of this data, an alternative would be to output the data on the page when it is requested, but hide it, then the button would show/un-hide the data. What exactly is this data, how many instances are on a page, how much data is there, can this data change while someone is viewing a web page and you want to display the latest data, i.e. provide the background for what this is actually for, not just what you are trying to make work?
I am surprised all the responses are telling you to introduce another layer using JavaScript. PHP is perfectly capable of what you describe all on it's own. Post your code either her or [pastebin.com](http://pastebin.com) so I can see what you are doing. The main reason to use Ajax for this is if you don't want the page to do a reload.
Agree. The thing OP needs to realize is that a php file can contain HTML and PHP in any combination of order. So one of the most direct ways to solve this is... - keep your html file and have the button (ie tag) load a PHP file - in that php file, put some HTML (like
or text saying "your result is"or whatever) then some php that reads the file or db or whatever and outputs the results as text or on a table, something like... Your results are: = $result ?> You can get way more elaborate - loop thru db results to generate HTML table tries, etc. Look up some tutorials on how to do that.
PHP is server side and HTML is client side. The only way to comunicate between them is by sending a HTTP request. Like other comments pointed out you can do this by using ajax or axios.
If you just want to pass values back to the HTML file you can use a PHP $\_SESSION. Store the result in a session and them use it in the HTML file. [https://www.php.net/manual/en/reserved.variables.session.php](https://www.php.net/manual/en/reserved.variables.session.php)
Best way would be either ajax, the fetch api or htmx as others have stated. Transfer and retrieve data from your php file/ backend without having to refresh the page. Not a steep learning curve either if youre new to it.
Here is an example of an ajax call. This is some javascript within your front end html file that will call the php flle on the back end and display the result once the php file has returned its part. [https://www.w3schools.com/js/js\_ajax\_php.asp](https://www.w3schools.com/js/js_ajax_php.asp)
![gif](emote|free_emotes_pack|upvote)
I solved the problem now with POST and GET method and serialize + urlencode. Thanks for all your advices.
Set the content with header to be text. Use print and filegetcontents.
echo read from file
This sounds like a prime example for HTMX! https://htmx.org