Make Dynamic Page Titles With PHP / mySQL

You can use the variable $page_title in the head section to create the page title within the meta tags. The example is shown below.

<?php
//get the url of the page with the curl() function
$my_url = curl();

$findme = 'mysite.com/category/subcategory';
$pos = strpos($my_url, $findme);

if ($pos == true) {

    $my_url_trimmed = str_replace("http://www.mysite.com/category/subcategory/", "", $my_url);

    $command = "SELECT tb1.id, tb1.col1, tb1.col2 from tablename as tb1 WHERE tb1.id='$my_url_trimmed';";
    $result = mysqli_query($db, $command);
    if ($result && mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {

            $space = " ";
            $gap = " | ";
            $location = $row["col1"];
            $page_title = $row["col2"] . $space . $location . $gap;

        }
    }
}

<title><?php echo $page_title; ?> </title>