jbuck20 Posted December 7, 2009 Share Posted December 7, 2009 I have created an image gallery and I want to display dynamic data in the <title> tag of the header. Currently the $title sets to the first record in the array and stays locked. When a new image is selected the $title in <title> does not change. The code is below. Thanks for the help. 1 $id = $row['id']; 2 $title = $row['title']; 3 $dimensions = $row['dimensions']; 4 $media = $row['media']; 5 //get the dimesions of the main image 6 $imageSize = getimagesize('images_art/'.$image); 7 $thumbSize = getimagesize('images_art/thumbs/'.$image); 8 ?> 9 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 10 <html xmlns="http://www.w3.org/1999/xhtml"> 11 <head> 12 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 13 <title><?php if (isset($id)) {echo "{$title}";} ?> 14 </title> 15 </head> Quote Link to comment https://forums.phpfreaks.com/topic/184298-display-dynamic-text-in-title/ Share on other sites More sharing options...
MadTechie Posted December 7, 2009 Share Posted December 7, 2009 You seam to be missing some code, where is $row['title'] set ? Quote Link to comment https://forums.phpfreaks.com/topic/184298-display-dynamic-text-in-title/#findComment-972989 Share on other sites More sharing options...
jbuck20 Posted December 7, 2009 Author Share Posted December 7, 2009 i left out the sql query code from the snippet, but the query does work and displays the images and titles in the body of the web page. i just can't get the <title> portion to change when a new image is selected. Quote Link to comment https://forums.phpfreaks.com/topic/184298-display-dynamic-text-in-title/#findComment-972997 Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 To change the title without a page reload (if it can be done) you will need to use Javascript. In order for the title to change you have to do a page reload with just PHP/HTML as the PHP is done on the server side and all HTML does is display data. Javascript can manipulate HTML on the client side. So yea, if it can be done you will have to use Javascript or force a page reload each time someone selects a new image. Quote Link to comment https://forums.phpfreaks.com/topic/184298-display-dynamic-text-in-title/#findComment-973000 Share on other sites More sharing options...
MadTechie Posted December 7, 2009 Share Posted December 7, 2009 the JS is simple document.title="Your title"; Quote Link to comment https://forums.phpfreaks.com/topic/184298-display-dynamic-text-in-title/#findComment-973011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.