Creating website via SQL table and PHP object I wanted to try keeping the content of a website (mostly) in a SQL table and have made the basic template for the body.  Set the $pageName and include this template.

class Page {
  public $content = [];
  public $heading;
}

$page = new Page();

$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
/* check connection*/
if ($conn-&gt;connect_errno) {
  die("Failed to connect with MySQL: " . $conn-&gt;connect_errno);
};

$sql = "SELECT type, heading1, content1, style FROM $table WHERE page = '$pageName' ORDER BY ord";
$result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
        switch($row['type']){
          case "content":
            $page-&gt;content[] = array("content" =&gt; '&lt;p&gt;' . $row['content1'] . '&lt;/p&gt;', "heading" =&gt; "&lt;h3&gt;" . $row['heading1'] . "&lt;/h3&gt;", "style" =&gt; $row['style']);
            break;
          case "heading":
            $page-&gt;heading = "&lt;h1&gt;" . $row['heading1'] . "&lt;/h1&gt;";

            if ($row['content1']) {
              $page-&gt;heading .= "&lt;h2&gt;" . $row['content1'] . "&lt;/h2&gt;";
            }
        }
    }

  mysqli_close($conn);
 ?&gt;

&lt;header&gt;
  &lt;?php echo $page-&gt;heading; ?&gt;
&lt;/header&gt;


&lt;?php
for ($i=0; $i &lt; count($page-&gt;content); $i++) {
  echo "&lt;section class='content ".$page-&gt;content[$i]["style"]."'&gt;";
  echo $page-&gt;content[$i]["heading"];
  echo $page-&gt;content[$i]["content"];
  echo "&lt;/section&gt;";
}
?&gt;


I'm planning on adding more types than content and heading as needed.  I will also add includes such as HTML head/meta, navbar, and footer.

I just wondered what people thought of this (besides "why?").
It's simple. It looks nice enough.

But please, for the love of little Bobby Tables, bind your variables: http://www.wikihow.com/Prevent-SQL-Injection-in-PHP . That would work out to:

$stmt-&gt;bind_param("s", $pageName);


once you've created a prepared statement.

Also, consider using a numeric identifier which maps to a pageName, similar to how StackExchange maps 174740 to "creating-website-via-sql-table-and-php-object".

Wrap very long lines, please. After commas in your array() would be a good place.

You didn't show your schema. I hope you have a compound unique key on (page_name, ord). Perhaps it's your PK.

Sometimes HTML tags aren't perfectly nested, and such errors might become stored in your database. I don't know what the PHP equivalent of python BeautifulSoup is, but at the DB->web interface your loop has an opportunity to ensure only well-formed HTML is sent to clients.