Website Title Change for each database entry for PHP

Hi There,

I would like my webpage title to change for each sub-site that I visit say I go to player A I want the website name to say CNGHLDB-Player A and If I go to player B profile it would change to say CNGHLDB-Player B I have the names in my php script so I am assuming it shouldn’t be to hard to do the coding for it, but I am not sure how to do it.

[php]CNGHLDB

<? // Connects to your Database mysql_connect("", ", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); //Get PlayerID from URL $iPlayerID = $_GET["PlayerID"]; $iNationID = $_GET["NationID"]; $oPlayerInfo = mysql_query(" SELECT Players.PlayerID, Players.FirstName, Players.LastName, Players.Position, Players.Height, Players.Weight, Players.DOB, CNGHLTeams.CNGHLRights, NHLTeams.Team, Players.CNDraftYR, DraftTeam.DraftID, Players.CNDraftPOS, Countries.Nation, Players.NationID, DraftTeam.DrTeam FROM Players Left JOIN CNGHLTeams ON Players.CNGHLID=CNGHLTeams.CNGHLID Left JOIN NHLTeams ON Players.TeamsID=NHLTeams.TeamID Left JOIN Countries ON Players.NationID=Countries.NationID Left JOIN DraftTeam ON Players.DraftID=DraftTeam.DraftID WHERE Players.PlayerID=$iPlayerID ORDER BY Players.LastName; ") or die(mysql_error()); while($row = mysql_fetch_array($oPlayerInfo)) { Print ""; ECHO "
"; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO "

 

"; Print "

"; Print ""; Print ""; Print ""; Print ""; Print ""; $DOB = $row[DOB]; //dd.mm.yyyy $user_date = new DateTime($DOB); $curr_date = new DateTime(); $age_cal = $curr_date->diff($user_date); Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print " [/php] The coding that pulls there names that I would want to use is Firstname and Lastname or I have the simpler full name that include both first and last names. Thanks for your help!

".$row['FirstName']." ".$row['LastName']." 

Birthdate: ".$row['DOB']." Age: ".$age_cal->y;"
"; Print "
Nation: ".$row['Nation']." CNGHL Team: ".$row['CNGHLRights']. "
Position: ".$row['Position']. " Weight: ".$row['Weight']. "
Height: ".$row['Height']. " NHL Team: ".$row['Team']. "
Draft Year: ".$row['CNDraftYR']." Draft Position: ".$row['CNDraftPOS']."
Drafted By: ".$row['DrTeam']." 
 

The title of this topic is a bit confusing. What I want is for each page to be dynamically changed by php.

I think you can use loop and change the title by id

[php]while ($row = mysql_fetch_array($name))
{
echo “CNGHLDB-”’.$name.’"";
}[/php]

CNGHL, Yes, Hanchan is correct. To add to that, just remember that PHP is handled SERVER-SIDE.
All of it’s code is handled BEFORE the browser gets any of the resulting code. Javascript/JQuery and
CSS is all handled CLIENT-SIDE AFTER the browser gets control of the output of the PHP code.

Therefore, you can actually set up ANY part of your HTML page using ANY of your database info.
You just have to pull the information to display before you create your HTML page and enter the
data inside the variables while building the page. I often use the code Hanchan posted for you.
I also add things like changing the background color of the page inside a tag based on
a user’s preferences. Headers, footers, menus, color and just about anything in HTML can be
customized by your PHP code.

Just wanted you to think outside the box and realize the possibilities… Good luck!

Thanks for both of your help, one thing I am not sure of is where to put the code.

[php]

<? // Connects to your Database mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); //Get PlayerID from URL $iPlayerID = $_GET["PlayerID"]; $iNationID = $_GET["NationID"]; $oPlayerInfo = mysql_query(" SELECT Players.PlayerID, Players.FirstName, Players.LastName, Players.Position, Players.Height, Players.Weight, Players.DOB, CNGHLTeams.CNGHLRights, NHLTeams.Team, Players.CNDraftYR, DraftTeam.DraftID, Players.CNDraftPOS, Countries.Nation, Players.NationID, DraftTeam.DrTeam, Players.FullName FROM Players Left JOIN CNGHLTeams ON Players.CNGHLID=CNGHLTeams.CNGHLID Left JOIN NHLTeams ON Players.TeamsID=NHLTeams.TeamID Left JOIN Countries ON Players.NationID=Countries.NationID Left JOIN DraftTeam ON Players.DraftID=DraftTeam.DraftID WHERE Players.PlayerID=$iPlayerID ORDER BY Players.LastName; ") or die(mysql_error()); while ($row = mysql_fetch_array($FullName)) { echo "CNGHLDB-\"'.$FullName.'\""; } [/php] Am I doing it right replacing the $name with $FullName as that is the code I am pulling? When I run this code I do not get the result I was looking for.

Well, your general layout for a web page would be like this:
[php]

Untitled Document [/php] So, with the added code you posted, it would look more like this: [php] <?PHP // Connects to your Database mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error());

//Get PlayerID from URL
$iPlayerID = $_GET[“PlayerID”];
$iNationID = $_GET[“NationID”];

$oPlayerInfo = mysql_query("
SELECT Players.PlayerID, Players.FirstName, Players.LastName, Players.Position, Players.Height, Players.Weight, Players.DOB, CNGHLTeams.CNGHLRights, NHLTeams.Team, Players.CNDraftYR, DraftTeam.DraftID, Players.CNDraftPOS, Countries.Nation, Players.NationID, DraftTeam.DrTeam, Players.FullName
FROM Players
Left JOIN CNGHLTeams
ON Players.CNGHLID=CNGHLTeams.CNGHLID
Left JOIN NHLTeams
ON Players.TeamsID=NHLTeams.TeamID
Left JOIN Countries
ON Players.NationID=Countries.NationID
Left JOIN DraftTeam
ON Players.DraftID=DraftTeam.DraftID
WHERE Players.PlayerID=$iPlayerID
ORDER BY Players.LastName;
") or die(mysql_error());
$row = mysql_fetch_array($oPlayerInfo);
?>

<?PHP echo "CNGHLDB-" . $row["FullName"]; ?>"; [/php] Something like that. Not tested, just explaining... And, note some minor changes in your table accesses. There were some minor errors. Good luck!

Thanks! That did the trick!

Glad it works! Congrats! Always a nice warm feeling when you solve a puzzle…

PS: thanks for the Karma! Glad I could help!

Sponsor our Newsletter | Privacy Policy | Terms of Service