homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Creating a dynamic title from database?
How to post data from database into title?
malone19




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

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...

 

chasehx




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

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>

Readie




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

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>
...';

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved