-3

I have several div tags and am using style display: block and none. Depending on a user selection, a javascript function will display one div and the others will be hidden. The div tags contain php code, access a mysql database and display data. Will the mysql code be executed each time the block is displayed? Or does that just happen once? with the resulting html displayed/hidden based on user selection?

Sue
  • 3
  • 3
  • 2
    php is serverside. it will run when the page loads. if you want to run it only when div is shown, you will need to use AJAX. view a page source, you will see the php has run even if hidden by js –  Oct 29 '17 at 22:24
  • [Client vs Server](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – GolezTrol Oct 29 '17 at 22:29
  • Posting some of your code might help. – david25272 Oct 29 '17 at 22:51

1 Answers1

0

The PHP code containing the MySQL query is only executed when the pages is rendered by the server back-end.

Changing the style only changes the client side state of the page and no PHP or MySQL will be executed (unless you add an explicit AJAX call to the server-side).

ascu
  • 1,029
  • 1
  • 19
  • 33
  • Thanks for shedding light on, what to some, might seem like an obvious answer. Maybe this can provide some insight into how various programming elements work together, for those of us less knowledgeable :) – Sue Oct 30 '17 at 14:07