Medyman
07-23-2007, 06:06 PM
Hey all...
I'm trying to build a simple CMS system to easily update a "recent updates/news" section on a website I'm building.
This is the first time I'm doing something like this, so please bear with me.
I followed a tutorial at php-mysql-tutorials.com and learned a lot.
I have it working as the tutorial says. I wanted to tweak it a little, however. So I don't know how I would do this.
Here is the PHP. This lists all of the available articles in the DB and then makes a list.
<?php
include 'config.php';
include 'opendb.php';
// if no id is specified, list the available articles
if(!isset($_GET['id']))
{
$self = $_SERVER['PHP_SELF'];
$query = "SELECT id, title FROM news ORDER BY id";
$result = mysql_query($query) or die('Error : ' . mysql_error());
// create the article list
$content = '<ol>';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
list($id, $title) = $row;
$content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n";
}
$content .= '</ol>';
$title = 'Available Articles';
} else {
// get the article info from database
$query = "SELECT title, content FROM news WHERE id=".$_GET['id'];
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$title = $row['title'];
$content = $row['content'];
}
include 'closedb.php';
?>
<html>
<head>
<title>
<?php echo $title; ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
// ... some css here to make the page look nicer
</style>
</head>
<body>
<table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
<tr>
<td bgcolor="#FFFFFF">
<h1 align="center"><?php echo $title; ?></h1>
<?php
echo $content;
// when displaying an article show a link
// to see the article list
if(isset($_GET['id']))
{
?>
<p> </p>
<p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Article List</a></p>
<?php
}
?>
</td>
</tr>
</table>
</body>
</html>
What I want to do is show ALL of the articles. So, how would i do this without the whole "id" bit.
The second part would be that I need a way to delete an entry for the mySQL table (i haven't attempted this yet, might be able to figure it out on my own)
Thanks!
I'm trying to build a simple CMS system to easily update a "recent updates/news" section on a website I'm building.
This is the first time I'm doing something like this, so please bear with me.
I followed a tutorial at php-mysql-tutorials.com and learned a lot.
I have it working as the tutorial says. I wanted to tweak it a little, however. So I don't know how I would do this.
Here is the PHP. This lists all of the available articles in the DB and then makes a list.
<?php
include 'config.php';
include 'opendb.php';
// if no id is specified, list the available articles
if(!isset($_GET['id']))
{
$self = $_SERVER['PHP_SELF'];
$query = "SELECT id, title FROM news ORDER BY id";
$result = mysql_query($query) or die('Error : ' . mysql_error());
// create the article list
$content = '<ol>';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
list($id, $title) = $row;
$content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n";
}
$content .= '</ol>';
$title = 'Available Articles';
} else {
// get the article info from database
$query = "SELECT title, content FROM news WHERE id=".$_GET['id'];
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$title = $row['title'];
$content = $row['content'];
}
include 'closedb.php';
?>
<html>
<head>
<title>
<?php echo $title; ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
// ... some css here to make the page look nicer
</style>
</head>
<body>
<table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
<tr>
<td bgcolor="#FFFFFF">
<h1 align="center"><?php echo $title; ?></h1>
<?php
echo $content;
// when displaying an article show a link
// to see the article list
if(isset($_GET['id']))
{
?>
<p> </p>
<p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Article List</a></p>
<?php
}
?>
</td>
</tr>
</table>
</body>
</html>
What I want to do is show ALL of the articles. So, how would i do this without the whole "id" bit.
The second part would be that I need a way to delete an entry for the mySQL table (i haven't attempted this yet, might be able to figure it out on my own)
Thanks!