Supposing I have the following script
<div id="something">
<?php
// execute a loop
?>
</div>
<script>
//use jquery to show "something" div block on and off <toggle> by a button click event, for example
</script>
My question is about whether or not the loop in the php tag code is executed each time the div is to be displayed. I think this is not a good way to handle this for possible performance issues, but I have been unable to find another way around to deal with this. Thank you for any advice and corrections.
No the PHP will not execute in this case. PHP is a server side scripting language. When you nest some PHP in your HTML code, the PHP is executed on the server side, possibly producing some HTML. When the client gets the page, they will only ever see HTML code.
On the web server:
In the browser:
Now, JavaScript is a client side language, so you might ask if I put JavaScript code in the div, would it execute every time I show/hide it? The answer is also no. When you show/hide elements on the page with jQuery, they still exist on the page, only their styles have changed. If you were to add a script element to the page, this would indeed be executed once for each time you added it.