Welcome to WebmasterWorld Guest from 54.145.104.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Creating a dynamic title from database?

How to post data from database into title?

     
3:30 pm on Jan 11, 2010 (gmt 0)

5+ Year Member



I'm trying to make the title for each product unique on my site but am finding it problematic, the way the site is set up the index.php contains the titles for each page.

The static pages appear like this:

case "RugCare": $title = "Rug Care, Cleaning & Maintenance: Little-Persia";
$content_for_layout = $_GET['action'];
break;

case "Gabbeh": $title = "Gabbeh rugs: Little-Persia";
$content_for_layout = $_GET['action'];
break;

case "RugDesign": $title = "Persian & Oriental Rug Layout and Design: Little-Persia";
$content_for_layout = $_GET['action'];
break;

For the dynamic product pages I want to add something dynamically (just now there is no title for them so it uses a default) for example:

case "view_rug": $title = "<some sort of echo or post statement - reference number> - <echo/post - make> Rug <echo/post - length> x <echo/post - width>";
if (!intval($_GET['id'])) {
header("Location: [$base_url...]
die();... there's further code for this source but I don't think it's relevant.

Any ideas on how to phrase it? When I put in code within the " " it's just putting the code in the title...

6:04 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



I like

$con = mysql_connect("server","user","pass");
$db = mysql_select_db("your_db",$con);
$sql = "SELECT title FROM your_table WHERE qualifier=value";
$res = mysql_result(mysql_query($sql),0);

$title = $res;
include('header.php');

inside header.php:

<html>
<head>
<title><? echo $title; ?></title>

11:41 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



If, as I thought you might be when I read your post you are simply having something like:

echo '...
<title> $title </title>
...';

Then the reason it is not dynamically changing the title is, when echoing or printing a variable, you need to concatenate it, like so:

echo '...
<title>' . $title . '</title>
...';
 

Featured Threads

Hot Threads This Week

Hot Threads This Month