89Views2Replies

Author Options:

When using PHP, does it matter where you place the code? Answered

Might seem like a silly question but is it better to place all your PHP code at the top of the page, then echo it where you want it to be, or to keep the code all in one spot?

For example,
Option One:

<?php code goes here at the top ?>

[rest of webpage]

<h2><?php echo ' $random_thing' ?></h2>


Option Two:

<php connect blah blah select blah;
 echo ' $random_thing';
?>

Hopefully that makes sense...

Discussions

0
None
Lithium Rain

8 years ago

I adhere to the school of thought that scattering any type of code throughout html is less than optimal and often makes for ugly, hard-to-fix code (not that it's a hard-and-fast rule for all case, though).

0
None
Jayefuu

8 years ago

I never bother. And sometimes you need input from the user.