Page 1 of 1
Dynamic page title (product description)
Posted: Thu Apr 05, 2012 2:19 am
by mlungisi
HI
Dynamic page title (product description)
I am trying to set my page title to reflect product description when I view the product page. Product info is sourced from MySql database.
The website do have pages like (about us, contact us, terms and condition, links etc) but in this case I need change for the products that are pulled from database.
The line that pulls description = <div class="block-yellow"><h5 class="padding-5"><?php echo $Pagedescr?></h5></div>
I’ve tried to but $pagedescr in my code but it doesn’t work.
<title><?php
if (isset($pageTitle)) {
echo $pagedescr;
} else {
echo "Name of the company";
}
?></title>
This is how the page is called:
http://company.com/?page=Product&id=77
Please help, I’ve got no much experience in PHP.
Thanks
Re: Dynamic page title (product description)
Posted: Thu Apr 05, 2012 2:49 am
by twinedev
Well we would need to see more of your code... What sets $pageTitle? what is its relationship to $pagedescr that you are echoing based on it? Are the variables named the exact way you have them? $Pagedesc and $pagedescr are two separate variables in PHP.
-Greg
Re: Dynamic page title (product description)
Posted: Thu Apr 05, 2012 2:59 am
by mlungisi
HI Twinedev, sorry made a mistake there;
Corrected code is: title><?php
if (isset($pagedescr)) {
echo $pagedescr;
} else {
echo "Name of the company";
}
?></title>
$Pagedescr = Page description - this gets the product description from database
Re: Dynamic page title (product description)
Posted: Thu Apr 05, 2012 7:27 am
by social_experiment
Code: Select all
<title>
<?php echo (isset($pagedescr)) ? $pagedescr : 'Name of company'; ?>
</title>
You can shorten it a bit by using the ternary operator
mlungisi wrote:$Pagedescr = Page description - this gets the product description from database
Also, this still isn't how you retrieve the data from the database, retrieval should be something using a SQL query;
Re: Dynamic page title (product description)
Posted: Thu Apr 05, 2012 7:34 am
by mlungisi
Query
if($item_count==1){
$Pagedescr = $data['ItemId'].': '.$data['ItemName'];
}elseif($data['GroupView']==3){
$Pagedescr = 'Product Group: '.$data['Group'];
}
Re: Dynamic page title (product description)
Posted: Thu Apr 05, 2012 7:45 am
by social_experiment
Code: Select all
<?php
if($item_count==1){
$Pagedescr = $data['ItemId'].': '.$data['ItemName'];
}elseif($data['GroupView']==3){
$Pagedescr = 'Product Group: '.$data['Group'];
}
// is there an else statement below this?
?>
The else-if statement usage here seems a bit wrong; to my thinking (and to those of the example in the php manual) the else if statement is still related to the $item_count, to check if it is not equal to 1, larger to one, smaller than one. Why not have an else statement, are there additional code below the else-if statement?

It's still not the query though
Re: Dynamic page title (product description)
Posted: Fri Apr 13, 2012 7:17 am
by mlungisi
HI, i'm back from Easter holiday and hope you had a safe break.
The website is
http://www.radiant.co.za
Product view:
http://www.radiant.co.za/?page=Product&id=JH108&group=
I want to show the name of the product on title. Product name = JH108: Chandelier 240v - Tellus 3-light bar
Also this will help when users share the product page on social network, the product name will be automatically posted.
The product name/description is pulled from MySQL by <?php echo $Pagedescr?> and that's what i want to put in the site title.