Question

This is more of a philosophical question, and the first part of this question is for other noobs who are struggling with the same ideas.

A few months ago I learned how to put php on an html page, let it read the db and populate variables while the DOM is being constructed. Note that I put the php ABOVE the html and it works fine.

<?php
   open db
   read table
   list variables
?>
<html>
  <head>
  </head>
  <body>
    <div id="mydiv"><? echo $lastname ?></div>
  </body>
</html>

A lot of my stuff on different pages is repetitive, so I tried to "include" (above the html) routine stuff with no success.

<?php include '../php/myroutinestuff.php' ?>
<html>
  <head>
  </head>
  <body>
  <body>
</html>

But I could get "small includes" to work if I put them within the body of the html. So a couple of days ago I REALLY needed to do the includes and found that if I put a "big include" within the html (not above it), everything works great.

<html>
  <head>
    <?php include '../php/myroutinestuff.php' ?>
  </head>
  <body>
    <div><?php echo "$lastname" ?>
  <body>
</html>

This got me thinking about the "best way", "standard way", "the way the experts do it" for reading data from a db and populating a DOM.

Questions:

  1. Do you routinely use PHP on an html page prior to loading to let the server populate the elements?

  2. Do you NEVER use PHP on an html page, and ONLY use ajax calls after loading to populate a page?

  3. Do you use a mix of the two? What criteria do you use?

  4. Are there other approaches to this issue?

Thanks very much!

Was it helpful?

Solution

this is your choice every time and there isn't any specific method. for me when i have a small project or small page i will mix php and html, but if the pages goes to be large i will put html,php and mysql in some specific files...

the important point is you can go back and read the code and edit it easily any time. however there are some methods for team working too. Google "object oriented programming" or "oop" for more information...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top