hello fellow developers,

i have built my website, how it works is it includes the header and footer through php and the rest of the content is in its corresponding file, but would it be possble to have the rest of the content in a mysql database and create pages like that dynamically (kind of like wordpress does), and if someone has a spare moment could you show me how this is done?

<? include("header.php"); ?>

--main content goes here

<? include("footer.php"); ?>

Website: http://www.shadowscape.co.uk

Thanks,

Nathaniel Blackburn

just select the main content from a table and show it

example:

<?php 
include("header.php");
$page = "myPage"; 
include("showPage.php");
include("footer.php"); 
?>

and for showPage.php

<?php 
	$db = new PDO("mysql:host=$host;dbname=$database", $dbUser, $dbUserPasswod);
	$query = "SELECT TXT FROM pages WHERE page = ?";
	$statement = $db->prepare($query);
	$statement->execute(array($page));
	if($statement->errorCode()!="00000")
	{
		$error = $statement->errorInfo();
		throw new Exception($error[2],(int)$error[0]);
	}
	$result = $statement->fetchAll(PDO::FETCH_ASSOC);
	if(count($result)>0)
	{
          echo $result[0]["TXT"];
	}

?>

But even this is a hybrid of procedural and OOP …. Have ever consider to move just to OOP ?

Thanks for your help, i managed to make my own navigation system

Nathaniel Blackburn

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.