the table has 5 columns: id, title, desciption, date, author. Here is the code below. Please help
Code: Select all
<?php
include('config.php');
// Get the joke text from the database
$id = $_GET['id'];
$joke = @mysql_query(
"SELECT title, id FROM joke WHERE id='$id'");
if (!$joke) {
exit('Unable to load the joke from the database.');
}
if (mysql_num_rows($joke) > 1) {
exit('Could not locate the specified joke ID.');
}
$joke = mysql_fetch_array($joke);
$title = $joke['title'];
// Filter out HTML code
$title = htmlspecialchars($title);
// If no page specified, default to the first page ($page = 0)
if (!isset($_GET['page'])) {
$page = 0;
} else {
$page = $_GET['page'];
}
// Split the text into an array of pages
$textarray = spliti('\[PAGEBREAK]', $title);
// Select the page we want
$title = $textarray[$page];
// Bold and italics
$title = str_replace(array('[b]', '[B]'), '<strong>', $title);
$title = str_replace(array('[eb]', '[EB]'), '</strong>', $title);
$title = str_replace(array('[i]', '[I]'), '<em>', $title);
$title = str_replace(array('[ei]', '[EI]'), '</em>', $title);
// Paragraphs and line breaks
$title = ereg_replace("\r\n", "\n", $title);
$title = ereg_replace("\r", "\n", $title);
$title = ereg_replace("\n\n", '</p><p>', $title);
$title = ereg_replace("\n", '<br />', $title);
// Hyperlinks
$title = eregi_replace(
'\\[L]([-_./a-z0-9!&%#?+,\'=:;@~]+)\\[EL]',
'<a href="\\1">\\1</a>', $title);
$title = eregi_replace(
'\\[L=([-_./a-z0-9!&%#?+,\'=:;@~]+)]([^\\[]+)\\[EL]',
'<a href="\\1">\\2</a>', $title);
$PHP_SELF = $_SERVER['PHP_SELF'];
if ($page != 0) {
$prevpage = $page - 1;
echo "<p><a href=\"$PHP_SELF?id=$id&page=$prevpage\">".
'Previous Page</a></p>';
}
echo "<p>$title</p>";
if ($page < count($textarray) - 1) {
$nextpage = $page + 1;
echo "<p><a href=\"$PHP_SELF?id=$id&page=$nextpage\">".
'Next Page</a></p>';
}
?>