...

View Full Version : Display article's title in title tag



Masterslave
02-08-2006, 05:48 PM
Hi all,

I want to show the article's title in the title tag.
But I can't display the title from the article because the title tag is loaded first and the the rest of my page.
I have a solution with javascript but if you haven't enable javascript, you'll see nothing so I want to do this with PHP, but how.

Javascript solution:

function synctitle(title)
{
document.title = document.title + ' | ' + title;
}


$title = " SELECT titel
FROM $artikelentable
WHERE ID = '" .$_GET['ID'] . "'";
$showtitle = mysql_query($title) or die (mysql_error());
?>
<body onload="synctitle('<?=mysql_result($showtitle, 0)?>');">
This works but I want to make this in PHP.

My articlepage:

<?
$query = " SELECT *
FROM $artikelentable
WHERE ID = '" .$_GET['ID'] . "'";
$result = mysql_query($query) or die (mysql_error());
?>
<body>
<div id="content">
<div class="artikel">
<? while ($row = mysql_fetch_assoc($result))
{?>
<h1><?=$row['titel'];?></h1>
<?=$row['content'];?>
<?}?>
</div>
</div>

Does anyone how to achieve this with PHP?
Thanks in advance!

Bill Posters
02-08-2006, 06:51 PM
I've only dabbled in PHP/MySQL, butů

If you perform the db query before the page markup starts to loads, then you can just as easily echo the appropriate row variable directly into the title element as well as using them later in the page's markup.

Masterslave
02-08-2006, 07:03 PM
Off course, I'll try that. Stupid me:p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum