Dynamic Title Generation using PHP and MySql

Thread Solved

Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Dynamic Title Generation using PHP and MySql

 
0
  #1
Dec 4th, 2008
Hello all,
For creating dynamic title tags,
I tried using

  1. <title>welcome<?php echo '$pagetitle';?></title>
  2. </head>
  3. <body>
  4. :
  5. :
  6. <?php
  7. :
  8. $pagetitle = '$row[2]';
  9. ?>
  10. //closing rest of the tags.

I get nothing displayed on title ! So i changed the code to,
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. :
  6. :
  7. :
  8. :
  9. :
  10. <?php
  11. :
  12. :
  13. :
  14. $pagetitle = '$row[2]';
  15. <title>welcome<?php echo '$pagetitle';?></title>
  16. ?>
  17. //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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Dynamic Title Generation using PHP and MySql

 
1
  #2
Dec 4th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 798
Reputation: pritaeas is on a distinguished road 
Solved Threads: 130
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Master Poster

Re: Dynamic Title Generation using PHP and MySql

 
1
  #3
Dec 4th, 2008
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)
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Dynamic Title Generation using PHP and MySql

 
0
  #4
Dec 4th, 2008
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.
Last edited by Kavitha Butchi; Dec 4th, 2008 at 9:25 am.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Dynamic Title Generation using PHP and MySql

 
0
  #5
Dec 4th, 2008
if you want valid html then you need to move it to the head section.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Dynamic Title Generation using PHP and MySql

 
1
  #6
Dec 4th, 2008
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.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Dynamic Title Generation using PHP and MySql

 
0
  #7
Dec 4th, 2008
Originally Posted by ShawnCplus View Post
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..
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC