DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Dynamic Title Generation using PHP and MySql (http://www.daniweb.com/forums/thread160658.html)

Kavitha Butchi Dec 4th, 2008 1:34 am
Dynamic Title Generation using PHP and MySql
 
Hello all,
For creating dynamic title tags,
I tried using

<title>welcome<?php echo '$pagetitle';?></title>
</head>
<body>
:
:
<?php
:
$pagetitle = '$row[2]';
?>
//closing rest of the tags.

I get nothing displayed on title ! So i changed the code to,
<html>
<head>
</head>
<body>
:
:
:
:
:
<?php
:
:
:
$pagetitle = '$row[2]';
<title>welcome<?php echo '$pagetitle';?></title>
?>
//closing rest of the tags.

Its now working. But is this the right way to use title tags in the middle of the code somewhere but not in the actuall <head> section of the page?!
Also, I tried using <meta> tags tooo randomly in the middle of the page code.
Though everything is working fine, i doubt i am actually coding in the wrong way. Is this the proper way to code? I chose this because the first version is displaying me nothing as $pagetitle gets value into it after empty title is displayed:(

Any advise will be appreciated. Thank you all in advance.

kkeith29 Dec 4th, 2008 4:44 am
Re: Dynamic Title Generation using PHP and MySql
 
the reason the first one didn't work was because you have to set the variable with the title you want before trying to echo it.

just put the title in the head section. at the top of the page add your title code and the echo it where i needs to be.

pritaeas Dec 4th, 2008 6:41 am
Re: Dynamic Title Generation using PHP and MySql
 
Well. It is correct, but if you want a clean separation between code and layout, I'd suggest you use templates. The html code goes into a template, with variables like title. After setting all your vars, you output the template. Nice and clean. (smarty.net)

Kavitha Butchi Dec 4th, 2008 9:23 am
Re: Dynamic Title Generation using PHP and MySql
 
Hi kkeith29 and pritaeas
Now I know how to put it in <head> section and retrieve values at the same time. But let me know , if doing it in the way i did might be a problem?! If not i shall leave it as coded but if there is a problem then i shall remove the <title> tags from the <body> and place it in the head section.
Thank you fr your patience and time.

kkeith29 Dec 4th, 2008 11:00 am
Re: Dynamic Title Generation using PHP and MySql
 
if you want valid html then you need to move it to the head section.

ShawnCplus Dec 4th, 2008 11:04 am
Re: Dynamic Title Generation using PHP and MySql
 
Aside from what they've said about validation just remove the quotes around the variable. Variables inside '' aren't parsed out so you won't get anything but that string. Either use "" or none at all when only echoing a variable.

Kavitha Butchi Dec 4th, 2008 11:17 am
Re: Dynamic Title Generation using PHP and MySql
 
Quote:

Originally Posted by ShawnCplus (Post 750178)
Aside from what they've said about validation just remove the quotes around the variable. Variables inside '' aren't parsed out so you won't get anything but that string. Either use "" or none at all when only echoing a variable.

Hi ShawnCplus and kkeith29,
Thankyou fr the valuable piece of info.
Cheers..


All times are GMT -4. The time now is 4:41 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC