I have some code in my PHP page which I have entered twice. I'd like to be able to write this only once.
What is the best way to do this? Can I put it into a function or a subroutine, and then call that? I'm very new to PHP and so am not sure of the correct syntax.
Only a small amount of information is different, and I have entered this code uniquely in the if and then in the else. The code that is the same (a form) I have twice. I've tried creating a function using:
function buildtable() { form/table stuff }
and then calling that just by using
echo "unique stuff here";
buildtable();
echo "more unique stuff here";
But it doesn't seem to be working properly. :p
Thanks. 🙂
Edit: the function is defined outside the if statement, just at the bottom of the page. Not sure if that matters. There are DB calls in the if statement too, which do not seem to be copied into the function.