Держи Код (работает 100%)!!!
MySQL:
Структура таблицы `comments`
CREATE TABLE `comments` (
`id` int(5) NOT NULL auto_increment,
`post` int(5) NOT NULL default '0',
`author` varchar(100) NOT NULL default '',
`text` text NOT NULL,
`date` date NOT NULL default '0000-00-00',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=12 ;
PHP Код:
<?php
error_reporting(NULL);
$dbhost = "localhost";
$dbuser = "user"; // Юзер в БД
$dbpass = "pass"; // Пароль Юзера
$dbname = "bd"; // Имя БД
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error connecting to database"
;
mysql_select_db($dbname);
$tableName="comments"; //Таблица с коментами
$targetpage = "ссылка на страницу.php"; //Страница, на которой выводим коменты
$limit = 10; //Выводим по 10 коментов на страницу
$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string($_GET['comments_page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
} ;
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
if ($page > 1){
$paginate.= "<a href='$targetpage?id=$id&comments_page=$prev'>Предыдущая</a>";
}else{
$paginate.= "<span class='disabled'>Предыдущая</span>"; }
if ($lastpage < 7 + ($stages * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?id=$id&comments_page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2))
{
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?id=$id&comments_page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?id=$id&comments_page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?id=$id&comments_page=$lastpage'>$lastpage</a>";
}
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?id=$id&comments_page=1'>1</a>";
$paginate.= "<a href='$targetpage?id=$id&comments_page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?id=$id&comments_page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?id=$id&comments_page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?id=$id&comments_page=$lastpage'>$lastpage</a>";
}
else
{
$paginate.= "<a href='$targetpage?id=$id&comments_page=1'>1</a>";
$paginate.= "<a href='$targetpage?id=$id&comments_page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?id=$id&comments_page=$counter'>$counter</a>";}
}
}
}
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?id=$id&comments_page=$next'>Следущая</a>";
}else{
$paginate.= "<span class='disabled'>Следущая</span>";
}
$paginate.= "</div>";
}
echo "<p>Всего Комментариив:</p>";
$result3 = mysql_query ("SELECT * FROM comments WHERE post='$id' LIMIT $start, $limit",$db);
if (mysql_num_rows($result3) > 0)
{
$myrow3 = mysql_fetch_array($result3);
do
{
printf ("<div class='comments_articles'><div class='comments_author_date'><p>Комментарий Добавил(а): <strong>%s</strong> <br/> Дата: <strong>%s</strong></p></div>
<div class='comments_text'><p>%s</p></div></div><br/>",$myrow3 ["author"],$myrow3 ["date"],$myrow3 ["text"] );
}
while ($myrow3 = mysql_fetch_array($result3));
echo $paginate;
}
?>
Форму добавление коментов сам пиши!