I am changing my web site from static html pages to php pages using includes and a mysql dbse. In the dbse table I store the blog body text and the blog title text, and the blog date. I have written a page I call 'previous_blogs.php' to list all the blogs in the database and they are linked to the particular blog. But with that I still have to create a separate .php page for each and every blog, this is what I want to get away from. I want all the links to point to one page - blog.php (for example) - which will have includes for headers, menus, footer, etc, and a query to pull just the blog title and blog body text, no matter which link was clicked on. It is this second page that I haven't figured out and can't seem to find the answer online. I guess I need to pass the variable 'id' from the first page to the second page so the second page knows what data to pull from the dbse. Correct?

The code for the first page is this -

<?php

    $usr = "somebody";
    $pwd = "someword";
    $db = "somedb";
    $host = "someserver";

    //connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

include("header.inc");

include("body.inc");

    // setup SQL statement
    $SQL = " SELECT * FROM blogs ORDER BY id DESC";

    // execute SQL statement
    $retid = mysql_db_query($db, $SQL, $cid);

    // check for errors
    if (!$retid) { echo( mysql_error()); }
    else {

        // display results
        while ($row = mysql_fetch_array($retid)) {
            $siteurl = $row["blog_page"];
            $sitename = $row["description"];

            echo ("<dd><a href='$siteurl'>$sitename</a></dd>\n");
        }
        echo ("</dt></p>");
    }

include("footer.inc");
?>

This first page works as I expect it to, so now I need to create the second page that will be called by all the links but with different body/title text from the database. That is the problem I am having, how to do that.

Any help would by much appreciated. Thanks.

Yep, that sounds about right. Something like
<a href="/blog.php?id=12345">View Blog</a>

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.