Saturday, September 18, 2010

Webdesign, chapter eleven: CMS part 3

I guess that at some point someone might actually want to display the content that they have added to their database, so that's what we're going to do now.
For this we just use the same file that we had used in chapter 6 and take out the content. Now at the very top (before the doctype) we're putting the code to get data out of our database, first we use the same connect that we used to get data into the DB, and we obviously select the same DB:
$connection = mysql_pconnect('localhost', 'xyious', 'password');
mysql_select_db("WebsiteDB", $connection) or die(mysql_error());
then we write a simple query to get the data, execute it, save the result in $result, get a single row from that and save that in $row:
$query = "SELECT * FROM xyious_content ORDER BY ID DESC";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
After that we start writing the actual web page, doctype, head, the links/imports for the css. Then as a title we use:
<title><?php echo $row[5]; ?></title>
then we continue with the closing tags and the opening div, at which point we add the following code:
<?php echo "<h1>" . $row[5] . "</h1>";
if ($row[6] != "") {
echo "<p style='text-align: center'>" . $row[6] . "</p>";
}
echo "<p>" . $row[7] . "</p>";
?>
In case you didn't remember, row 5 is the Headline, 6 is Description, 7 is Content.
Everything else remains the same as it has been in post6.
Right now we would have to make a reasonably specific page for every single web page, although we could already store all of the content in the database. That's obviously not very comfortable or useful, so we're going to change and add a few things soon.

No comments:

Post a Comment

Facebook