Forum Moderators: coopster
include 'connect.php';
$id = 'meta_id';
$title = 'page_title';
$pname = 'page_name';
$desc = 'meta_description';
$key = 'meta_keywords';
$aut = 'author';
$copyr = 'copyright';
$email = 'email';
$rating = 'rating';
$robots = 'robots';
$visit = 'revisit';
$exp = 'expires';
$dist = 'distribution';
$sql = "SELECT * FROM meta_data WHERE meta_id = 1 LIMIT 1";
$query = $db->query($sql);
$row = $query->fetch(PDO::FETCH_ASSOC);
unset ($row['meta_id']) ; // discard that one
foreach ($row as $desc => $content) {
echo "<meta name=\"$desc\" content=\"$content\" />\n" ;
}
<!DOCTYPE HTML>
<html>
<head>
<link rel="apple-touch-icon" href="apple_touch_icon.png"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php include_once('../includes/fetchmetadata.php'); ?>
<link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory-->
<title></title>
</head>
<body>
</body>
</html>
You would typically use the URL query string to specify the id, then use $_GET to get it.
// connect.php
<?php
$config['db'] = array(
'host' => 'localhost',
'username' => 'root',
'password' => 'pass',
'dbname' => 'database'
);
$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);
?>
// getmetadata.php
<?php
include 'connect.php';
$id = 'meta_id';
$title = 'page_title';
$pname = 'page_name';
$desc = 'meta_description';
$key = 'meta_keywords';
$aut = 'author';
$copyr = 'copyright';
$email = 'email';
$rating = 'rating';
$robots = 'robots';
$visit = 'revisit';
$exp = 'expires';
$dist = 'distribution';
$sql = "SELECT * FROM `meta_data` WHERE `meta_id` = {$page_id} LIMIT 1";
$query = $db->query($sql);
$row = $query->fetch(PDO::FETCH_ASSOC);
unset ($row['meta_id']) ; // discard that one
foreach ($row as $desc => $content) {
echo "<meta name=\"$desc\" content=\"$content\" />\n" ;
}
echo "<title>";
echo $row[$title];
echo "</title>\n";
?>
<?PHP
//### Set the page ID to retrieve data from database
$page_id = 4;
?>
<!DOCTYPE HTML>
<html>
<head>
<link rel="apple-touch-icon" href="apple_touch_icon.png"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php include_once('../includes/fetchmetadata.php'); ?>
<link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory-->
</head>
<body>
<p><a href="contact.php">contact</a></p>
<p><a href="products.php">products</a></p>
<p><a href="services.php">services</a></p>
<p><a href="home.php">home</a></p>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<link rel="apple-touch-icon" href="apple_touch_icon.png"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="page_name" content="services" /> <!-- dont want this field -->
<meta name="page_title" content="Our Services" /> <!-- dont want this field -->
<meta name="meta_description" content="introduction to our services offered at competitive prices" />
<meta name="meta_keywords" content="training, tuition, onsite, offsite" />
<meta name="author" content="author" />
<meta name="copyright" content="© Organisation, 2013" />
<meta name="email" content="organisations email" />
<meta name="rating" content="General" />
<meta name="robots" content="INDEX,FOLLOW" />
<meta name="revisit" content="7 Days" />
<meta name="expires" content="no data in this field at the moment" />
<meta name="distribution" content="Global" />
<title>Our Services</title>
<link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory-->
</head>
<body>
<p><a href="contact.php">contact</a></p>
<p><a href="products.php">products</a></p>
<p><a href="services.php">services</a></p>
<p><a href="home.php">home</a></p>
</body>
</html>
<!-- index.php -->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>website</title>
<link href="css/screen/screen.css" rel="stylesheet" type="text/css" media="screen">
</head>
<body>
<ul id="nav">
<li><a href="home">Home</a></li>
<li><a href="subjects">Subjects</a></li>
<li><a href="downloads">Downloads</a></li>
<li><a href="about">About</a></li>
<li><a href="contact">Contact</a></li>
</ul>
<div id="content">
<script src="js/jquery.js"></script>
<script src="js/general.js"></script>
</div> <!-- end of content div -->
</body>
</html>
// JavaScript general.js
//alert ('working'); //test
// loading content
// initial page loading
$(document).ready(function() {
$('#content').load('content/home.php');
// handle menu clicks
$('ul#nav li a').click(function() {
//alert('OK'); // test
var page = $(this).attr('href');
//alert(page); // test
$('#content').load('content/' + page + '.php');
return false;
});
});
<h1>Home Page</h1>
<br />
<p>This is the home page</p>
// index.php
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Website</title>
<link href="inc/styles.css" rel="stylesheet" type="text/css" media="screen">
</head>
<body>
<div id="header"><h1>Dynamic Site</h1></div>
<div id="menu">
<a href="index.php?page=home">Home</a>
<a href="index.php?page=contact">Contact</a>
<a href="index.php?page=about">about</a>
<a href="index.php?page=tutorials">tutorials</a>
</div>
<div id="content">
<?php
$pages_dir = 'inc';
if(!empty($_GET['page'])){
$pages = scandir($pages_dir, 0);
unset($pages[0], $pages[1]);
$page = $_GET['page'];
if (in_array($page.'.php', $pages)){
include $pages_dir.'/'.$page.'.php';
} else {
echo "Sorry that page does not exist.<br>You will be redirected in 5 seconds to the homepage.";
// need 5 second timer b4 page changes
header("refresh:5; index.php?page=home");
}
} else {
include ($pages_dir.'/home.php');
}
?>
</div>
</body>
</html>
//home.php content.php products.php in the inc folder
Welcome to the home page etc etc according to the page name
<?php
if ($_SERVER['REQUEST_URI'] == "/home.php" || $_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta name=\"title\" content=\"title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"description content goes here, called from DB!\">\n\n";
echo "<title>page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/contact.php" || $_SERVER['REQUEST_URI'] == "/contact.php") {
echo "<meta name=\"title\" content=\"title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"description content goes here, called from DB!\">\n\n";
echo "<title>page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/products.php" || $_SERVER['REQUEST_URI'] == "/products.php") {
echo "<meta name=\"title\" content=\"title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"description content goes here, called from DB!\">\n\n";
echo "<title>page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/services.php" || $_SERVER['REQUEST_URI'] == "/services.php") {
echo "<meta name=\"title\" content=\"title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"description content goes here, called from DB!\">\n\n";
echo "<title>page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/about.php") {
echo "<meta name=\"title\" content=\"title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"description content goes here, called from DB!\">\n\n";
echo "<title>page title goes here, called from DB!</title>\n\n";
} else {
echo "<meta name=\"title\" content=\"title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"description content goes here, called from DB!\">\n\n";
echo "<title>page title goes here, called from DB!</title>\n\n";
}
?>
|| $_SERVER['REQUEST_URI'] == "/index.php") on the first line and then all the way through?
include 'connect.php';
if ($_SERVER['REQUEST_URI'] == "/home.php" || $_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta name=\"title\" content=\"Home title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"Home keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"Home description content goes here, called from DB!\">\n\n";
echo "<title>Home page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/contact.php" || $_SERVER['REQUEST_URI'] == "/contact.php") {
echo "<meta name=\"title\" content=\"contact title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"contact keyword content goes here, called from DB! CONTACT\">\n";
echo "<meta name=\"description\" content=\"contact description content goes here, called from DB!\">\n\n";
echo "<title>contact page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/products.php" || $_SERVER['REQUEST_URI'] == "/products.php") {
echo "<meta name=\"title\" content=\"Products title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"products keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"products description content goes here, called from DB!\">\n\n";
echo "<title>products page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/services.php" || $_SERVER['REQUEST_URI'] == "/services.php") {
echo "<meta name=\"title\" content=\"Services title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"services keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"services description content goes here, called from DB!\">\n\n";
echo "<title>services page title goes here, called from DB!</title>\n\n";
} elseif ($_SERVER['REQUEST_URI'] == "/about.php") {
echo "<meta name=\"title\" content=\"About title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"About keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"About description content goes here, called from DB!\">\n\n";
echo "<title>About page title goes here, called from DB!</title>\n\n";
} else {
echo "<meta name=\"title\" content=\"Default title content goes here, called from DB!\">\n";
echo "<meta name=\"keywords\" content=\"Default keyword content goes here, called from DB!\">\n";
echo "<meta name=\"description\" content=\"Default description content goes here, called from DB!\">\n\n";
echo "<title>Default page title goes here, called from DB!</title>\n\n";
}
// The original source of the code is [url]http://support.open-realty.org/archive/index.php/t-1958.html[/url]