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

Current code:
<title><? echo PAGE_TITLE; ?></title>
Individual pages
define ("PAGE_TITLE", "Blablablablablabla");

I want to customize further the PAGE_TITLE in the file details.php ( ) 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.


Recommended Answers

All 3 Replies

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. 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 because 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 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.


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.