I have a php page that pulls a few hundred characters (distributed amongst 8 columns) of data from my database. It’s displayed on page one, but it needs to be available on page two as well. I am already submitting a form in order to make said page transitions.
What I’m wondering is if it is more efficient (or preferred for some other reason) to POST the data from the first page to the second, or if I should query the database for each page? There is another query for a different table on the first and second page as well, if that makes a difference.
Thank you very much!
Billy
If it is a truly small amount of data you have retrieved on your first page load, it may be more efficient to store it in
$_SESSIONrather than requerying it on subsequent pageloads. You should not post it to other pages through$_POST, however, as that would require sending all of the data down to the client browser and rendering it in HTML as some kind of form which would then get sent back up to the server in$_POST.$_SESSIONis the better option.The purpose of
$_POSTis to supply user input from client to server, while the purpose of$_SESSIONis to persist data between the client’s pageloads on the server side. That is exactly your situation.Always, the best way to know for sure is to profile your page loads with a tool like xdebug. Profile execution times when requerying and storing the data in
$_SESSIONto see which is more performant.