Dynamic page title (product description)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mlungisi
Forum Newbie
Posts: 15
Joined: Wed Apr 04, 2012 9:45 am

Dynamic page title (product description)

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Dynamic page title (product description)

Post 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
mlungisi
Forum Newbie
Posts: 15
Joined: Wed Apr 04, 2012 9:45 am

Re: Dynamic page title (product description)

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Dynamic page title (product description)

Post 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;
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
mlungisi
Forum Newbie
Posts: 15
Joined: Wed Apr 04, 2012 9:45 am

Re: Dynamic page title (product description)

Post by mlungisi »

Query

if($item_count==1){
$Pagedescr = $data['ItemId'].': '.$data['ItemName'];
}elseif($data['GroupView']==3){
$Pagedescr = 'Product Group: '.$data['Group'];
}
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Dynamic page title (product description)

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
mlungisi
Forum Newbie
Posts: 15
Joined: Wed Apr 04, 2012 9:45 am

Re: Dynamic page title (product description)

Post 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.
Post Reply