Hi there,

I have a classified website, built with custom PHP code. The problem is that the title of the entire site is the same. Attach files index.php and pOffers.php.

Please give ideas on how to call from database the title of the listing.

Tell me if you need more information.

http://dox.bg/files/dw?a=13b03f9f9c - index.php

http://dox.bg/files/dw?a=67ec789d73 - pOffers.php

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

Thanks for reply. How to do that?

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.

How to set where to get the information for $TitleFromDB

Thank very much for the help.

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>

Can I somehow define the page title from database.

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

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);

        }

Yes, you can do that as well

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.