Member Avatar for Borderline

I'm trying to find a way of automatically updating page titles on my site - occasionally, connections (owners, trainers, jockeys of horses) will appear as a variation of their original name (i.e. Mr M Smith may pop up as Mr Matt Smith). I update these in the database, but the page titles are hard coded, so they generally remain in their original format until I find time to tweak them.

I understand that there is a way in which the page title/meta data can be pulled from a database, but I'm struggling to find tutorials to describe what I'm looking for. I've tried using a tuotrial below, but am just resulting in a blank white page. I wondered if someone could point me in the right direction, please?

Head.php include:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><?php
if (isset($pageTitle)) {
echo $pageTitle;
} else {
echo "ARF Data";
}
?></title>
</head>

samplehorse.php

<?php include($_SERVER['DOCUMENT_ROOT'].'/*****/******.php');?>  <-- db connection -->

<?php
$sql = "SELECT horse, h_ctry
FROM `horse` WHERE h_link = '00001.php'
LIMIT 1";
$result = mysqli_query($sql) or die(mysql_error());
$row = mysqli_fetch_assoc($result);

$pageTitle = $row['horse'];
include("/testing/dynamicheaders/head.php");

Any advice much appreciated.

Recommended Answers

All 2 Replies

Member Avatar for Zagga

Hi Borderline,

In head.php, you should place the PHP code inside the <body> tag not the <title> tag ...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
if (isset($pageTitle)) {
    echo $pageTitle;
} else {
    echo "ARF Data";
}
?>
</body>

As @zagga suggested, put your code in the body to see it on the page, otherwise you won't see anything on the page... look at the browser tab to see your changes in the <title> element. cheers!

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.