3
Contributors
8
Replies
26
Views
4 Years
Discussion Span
Last Post by Webville312
0

If I am getting your question correctly, you need to define the titles of the pages in a file, lets say constants.php;
And so, you just keep on changing the titles for the different pages

0

If you're storing it in a database, simply make a call to it (preferably using parametised statements) and then in your HTML do this:

<title> <?php echo($TitleFromDB); ?> </title>

Which is echoing out the variable that you retrieved.

0

How to set where to get the information for $TitleFromDB

Thank very much for the help.

1

Or, you could create a file called constants.php then you store your title like so;

define("PAGE_TITLE","My Page Title");

Then u just include it in every page you want to display;

<title> <?php 
include_once('constants.php');
echo MY_PAGE_TITLE; ?> 
</title>
0

Can I somehow define the page title from database.

define("PAGE_TITLE","Call the title from database table with some code");
0

As you are probably aware, $TitleFromDB is the name of a variable, and could be anything you want.

The first thing you are going to want to do is connect to the database using something similar to the following:

<?php

    $Connect = mysqli_connect('localhost', 'USERNAME', 'PASSWORD', 'DATABASENAME');

    if(mysqli_connect_errno()){

        die("An error has occured connecting to the database.");

    }

?>

Then you shall want to extract the appropriate data from a table, let's assume that you want to extract data depending on the URL using the GET function.

$URL = $_GET['Title'];

And then do your select query depending on your database structure.

if ($stmt = mysqli_prepare($Connect, "SELECT Title FROM Classifieds WHERE Page = ?"))
        {
            mysqli_stmt_bind_param($stmt, 's', $URL);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_bind_result($stmt, $Title);

            while(mysqli_stmt_fetch($stmt))
            {

                ?><title> <?php echo($Title); ?></title> <?php

            }

            mysqli_close($Connect);

        }

Edited by Octet

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.