Question: How to pull info from MySQL to populate title tag?

Current code:
Include/common.inc.php
<title><? echo PAGE_TITLE; ?></title>
________________________________________
Individual pages
<?
include("include/common.inc.php");
define ("PAGE_TITLE", "Blablablablablabla");
ETC ECT ETC ETC ...
________________________________________

I want to customize further the PAGE_TITLE in the file details.php (www.mysite.com/details.php?listid=... ) to reflect information taken from MySQL such as the country name.
________________________________________
What I tried:

define ("PAGE_TITLE", "Properties for sale in $record[countryname]");
I tried $_GET, $_POST, $record, $data, etc ... nothing seems to pull the information.

Is it because it is in the "define" function?

I am at a loss. Any suggestions or links would be appreciated.

Warm regards.

Natasha

Recommended Answers

All 3 Replies

http://www.tizag.com/mysqlTutorial/index.php

Have a look through that (there's a lot there so just make sure you get what you need).

One thing, with your code: define ("PAGE_TITLE", "Properties for sale in $record[countryname]"); You should have: define ("PAGE_TITLE", "Properties for sale in $record['countryname']"); That will work if the array $record has an entry named 'countryname'.

That could just be the problem. If your having trouble getting the info out of the MySQL table then look at that tutorial and try stuff like print_r($array); to see what's in your array and weather or not it'w what you expected.

php.net is a good place to get the gist of a specific function.

EDIT: Oh, and another thing. If you do have trouble using the define function with variables like that then you can always just set a normal variable to the text that you want echoed to the screen in common.inc.php because common.inc.php assumes the variable scope of the line that it is called from. ie, it's like the code is being executed as if it was written in where the include() call is (but any variables that you set inside common.inc.php don't carry through to the rest of the original script, only definitions do.)

This is great info. Thanks. I will be "studying" it today. I think I am on the right path.

Just want to say thank you for your time.

Natasha

No problem.

I think I was misinformed about the $record['countryname'] thing. I think it works without the quotes. Sorry about that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.