First, I still have the PHP new kid shine on me so talk reeeeaaaallll slow. I've managed to beg, borrow or steal what I have so far from visiting the various forums lately so if anything looks clunky, let me know. Thanks in advance for the help.
Right now, I have a basic content-centric site and have designed a page template that is already using some php includes for the top nav, side nav and footer. For arguments sake, let's call it "pagetemplate.php"
The rest of the page has some areas that are custom to the specific page. By the way, these custom areas aren't grouped together in the template either. They're kind of spread throughout the code...don't know if it matters but fyi. These custom areas include:
An Article Title
The content of the article
A link to the next article
My db table looks like this:
current_url article_title content next_article_link next_article_link_text
www.mysite.com/article1 Page 1 Title Abc... www.mysite.com/article2 click here for article 2
www.mysite.com/article2 Page 2 Title Def... www.mysite.com/article3 click here for article 3.........
I've written the following script:
<?php
$db_host = "localhost";
$db_user="myusername";
$db_password="mypassword";
$self_url = sprintf('http%s://%s%s',
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': ''),
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
mysql_connect($db_host, $db_user, $db_password) or die("could not connect");
mysql_select_db("mytestdatabase") or die ("couldn't select DB");
$SQL = "SELECT * FROM mytable WHERE current_url='$self_url'";
$result = mysql_query($SQL) or die(mysql_error());
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result);
$currentpage=$row["current_url"];
$title= $row["article_title"];
$content= $row["article_content"];
$nextlink= $row["next_article_link"];
$nexttext= $row["next_article_text"];
}
$html = "<a href='$nextlink'>$nexttext</a>";
?>
I've saved the script as dbinclude.php and I've successfully put it into my template page like so:
<h1><?php include("dbinclude.php"); print $title?></h1>
<p><?php include("dbinclude.php"); print $content ?></p>
Check out our next featured article here: <h1><?php include("dbinclude.php"); print $html?></h1>
The script works in that if I create a couple of "test" pages (with the same name as the next_article_link) it will load the correct information from the corresponding record.
Where I'm stuck is that I need a way so that when they click on that "next featured article link" it automatically generates a new (dynamic?) page, on the fly, with the URL= http://$next_article_link and populates it with the data in the corresponding record. I don't actually want to create the pages to save anywhere I'm just trying to use one site template page that gets populated with corresponding db record data.
Is this feasible or will I have to duplicate hudreds of template pages first...pagetemplate.php/article1, article2, article3...etc. pages to accept the record data?