943,917 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2315
  • PHP RSS
Dec 4th, 2008
0

Dynamic Title Generation using PHP and MySql

Expand Post »
Hello all,
For creating dynamic title tags,
I tried using

php Syntax (Toggle Plain Text)
  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,
php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Dec 4th, 2008
1

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Dec 4th, 2008
1

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)
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Dec 4th, 2008
0

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.
Last edited by Kavitha Butchi; Dec 4th, 2008 at 9:25 am.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Dec 4th, 2008
0

Re: Dynamic Title Generation using PHP and MySql

if you want valid html then you need to move it to the head section.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Dec 4th, 2008
1

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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Dec 4th, 2008
0

Re: Dynamic Title Generation using PHP and MySql

Click to Expand / Collapse  Quote originally posted by ShawnCplus ...
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..
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: generating random id and save it into db
Next Thread in PHP Forum Timeline: how to connect to remote server usin ssh





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC