I found a pretty good solution. However, It adds a little extra to your code. I do not recommend using this method too much. I am a new PHP developer, so there are probably somethings this method can and cannot do.
also I cannot seem to prevent this method from loading a new page, so the best way is to add your php to the beginning of the file. This is also a better solution for using AJAX (my opinion)
if the current file is index.php...
make a form tag element
'<form action="index.php" method="post">'
'<input type="submit" name="helloWorld" value="hello World">'
'</form>'
here you will display the content of what you are trying for, with a click
'<article>'
'<?php echo myFunction(); ?>'
'</article>'
this next php markup can go anywhere as long as it it is in the same file... Unless you know how to work around. Best place is before the HTML.
'<?php '
'function myFunciton() {'
'if (isset($_POST[helloWorld])) {'
'echo "hello world"; ... your methods'
'}'
'}'
or you could directly access it without using a function
<body>
<form action="index.php" method="post">
<input type="submit" name="hello" value="hello">
<input type="submit" name="goodBye" value="goodBye">
</form>
<article>
<?php
if (isset($_POST[hello])) {
echo "This happens if you click hello";
}
if (isset($_POST[goodBye])) {
echo "This happens if you click goodBye";
}
?>
</article>
</body>