I have a couple of problems with my script. Its a simple cms script that displays an article list with links to each article, once the links are clicked it goes to a new page with the article displayed.
Now Ive set up pretty urls using the .htaccess file and it works fine. My only problem with it is that i cant figure out the proper syntax to use to link to the articles.
Ive changed the index.php?id=1 to a pretty url title in the database under the col 'longdesc'
so the database is set up like this
Id
Title
Post
Longdesc
This is were the link should be, i need it to goto the new 'longdesc' url instead.
eg :
http://www.site.com/this-is-a-post-name
instead of
http://www.site.com/index.php?id=1
Code: Select all
// make the article list
$content = '<ol>';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
list($id, $title) = $row;
>>>> $entry .= "<li><a href=\"$self\">$title</a></li>\r\n"; <<<<<<
}
$entry .= '</ol>';
Code: Select all
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /article/index.php [L] // article/ because im working on local at the moment.
Code: Select all
<?php
include 'library/opendb.php';
//get pretty uri
$uri = mysql_real_escape_string(basename($_SERVER['REQUEST_URI']));
//get id from db
$query = "SELECT `id` FROM `blog` WHERE `longdesc` = '$uri'";
$result = mysql_query($query);
if(mysql_num_rows($result) != 0)
{
$row = mysql_fetch_assoc($result);
$id = $row['id'];
}
// if no id is specif, list the available articles
if(!isset($id))
{
$query = "SELECT id, title FROM blog ORDER BY id";
$result = mysql_query($query) or die('Error : ' . mysql_error());
// make the article list
$content = '<ol>';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
list($id, $title) = $row;
$entry .= "<li><a href=\"$self\">$title</a></li>\r\n";
}
$entry .= '</ol>';
$title = 'Available Articles';
}
else
{
// get the article info from database
$query = "SELECT title, entry FROM blog WHERE id=".$id;
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$title = $row['title'];
$entry = $row['entry'];
}
?>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1 align="center"><?php echo $title; ?></h1>
<?php
echo $entry;
// when displaying an article show a link
// to see the article list
if(isset($_GET['$row']))
{
?>
<p align="center"><a href="http://127.0.0.1/article/">Article Directory</a></p>
<?php
}
?>
</body>
</html>
I have spent weeks trying to get this work.. i am a nub when it come to php.. but getting there though !
Cheers