Странициране - Поредния въпрос...хелп

EmPowerYou

Registered
Прегледах абсолютно всички теми за странициране, както и уроците. Хубаво, изкарва ми некви числа които като цъкам уж треа се сменя страницата, пък тя не се сменя. Разбира се, променям това което трябва, но без резултат. Още съм начинаещ в PHP, но горе-долу се справям, обаче тука зацепих.

Това ми е index.php, където се извеждат коментарите от db-то.

Код:
			<?
            include("include/db.php");
            $query = mysql_query("SELECT * FROM $mysql_table");
            $query = mysql_query("SELECT * FROM `$mysql_table` ORDER BY `id` DESC LIMIT 0 , 25");
            if(mysql_error()) {
            print(mysql_error());
            }
            while($row = mysql_fetch_array($query)) {
           
			$text=$row['content'];

			echo "<h1>".$row['title']."</h1><div class='comment'> ";
			
			//BBCode-а почва оттук
			$text=preg_replace("/\[b\](.+?)\[\/b\]/s", '<b>$1</b>',$text);

			$text=preg_replace("/\[i\](.+?)\[\/i\]/s", '<i>$1</i>',$text);

			$text=preg_replace("/\[u\](.+?)\[\/u\]/s", '<u>$1</u>',$text);

			$text=preg_replace("/\[quote\](.+?)\[\/quote\]/s", '<p style="width:auto; border:dashed 1px #CCC"><img src="images/quote.gif" />$1</p>',$text);

			$text=preg_replace("/\[quote\=(.+?)](.+?)\[\/quote\]/s", '<p style="width:auto; border="0">$1 êàçà:</p><p class="quote">$2</p>',$text);

			$text=preg_replace("/\[url\](.+?)\[\/url\]/s", '<a href="$1">$1</a>',$text);

			$text=preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/s", '<a href="$1">$2</a>',$text);

			$text=preg_replace("/\[img\](.+?)\[\/img\]/s", '<img src="$1" alt="Зареждане на изборажението" />',$text);

			$text=preg_replace("/\[color\=(.+?)\](.+?)\[\/color\]/s", '<span style="color:$1">$2</span>',$text);

			$text=preg_replace("/\[size=([1-5])\]((\s|.)+?)\[\/size\]/i", '<font size=\\1>\\2</font>', $text);

			$text=preg_replace("/\[code\](.+?)\[\/code\]/s",'Код:<br /><p class="code">$1</p>',$text);
			
			//Емотиконки
			$text=str_replace(":D",'<img src="smilies/biggrin.gif" />',$text);
			$text=str_replace(":P",'<img src="smilies/tongue.gif" />',$text);
			$text=str_replace(":-)",'<img src="smilies/blush.gif" />',$text);
			$text=str_replace("o.0",'<img src="smilies/blink.gif" />',$text);
			$text=str_replace("^_^",'<img src="smilies/closedeyes.gif" />',$text);
			$text=str_replace(":cool:",'<img src="smilies/cool.gif" />',$text);
			$text=str_replace(":pf:",'<img src="smilies/dry.gif" />',$text);
			$text=str_replace(":o",'<img src="smilies/ohmy.gif" />',$text);
			$text=str_replace(":)",'<img src="smilies/smile.gif" />',$text);
			$text=str_replace(":!:",'<img src="smilies/excl.gif" />',$text);
			$text=str_replace(":happy:",'<img src="smilies/happy.gif" />',$text);
			$text=str_replace(":huh:",'<img src="smilies/huh.gif" />',$text);
			$text=str_replace(":xaxa:",'<img src="smilies/laugh.gif" />',$text);
			$text=str_replace(":mad:",'<img src="smilies/mad.gif" />',$text);
			$text=str_replace(":^^:",'<img src="smilies/rolleyes.gif" />',$text);
			$text=str_replace(":(",'<img src="smilies/sad.gif" />',$text);
			$text=str_replace(":sleep:",'<img src="smilies/sleep.gif" />',$text);
			$text=str_replace(":hmm:",'<img src="smilies/unsure.gif" />',$text);
			$text=str_replace(":crazy:",'<img src="smilies/wacko.gif" />',$text);
			$text=str_replace(";)",'<img src="smilies/wink.gif" />',$text);
			
			$text = nl2br($text);

			echo "$text </p></div>";
       }




	   ?>

Ето и формата с която пиша коментарите:

Код:
<?
				include("include/db.php");
				?>
				<form action="post.php" name="form1" method="post">
				<p>Заглавие:</p><input type="text" name="title" size="40" />
				<p>Съобщение:</p><textarea name="content" rows="10" id="msg" cols="30"></textarea>
				<p><input type="submit" name="Submit" value="Публикувай!" class="submit" /></p>
				</form>
				<p class="comments">Коментари</p>
				<p><?
				$query = "SELECT id, title FROM news";
      			$result = @mysql_query($query);
				if ($result) {
       			while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
     			echo 'Заглавие:<br />'.$row['title'].'<br />
	  			<a href="del.php?id='.$row['id'].'"><button class="submit">Изтриване</button></a> 
	  			<a href="edit.php?id='.$row['id'].'"><button class="submit">Промяна</button></a>';
      			}
      			} else {
      			echo 'Коментарите немогат да бъдат изведени от базата данни.';
      			}
				?>

И предполагам ще ви потрябва include/db.php:

Код:
<?
$dbh=mysql_connect ("localhost", "root", "password") or die ('Немога да се свържа с базата от данни' . mysql_error());
mysql_select_db ("comments");
$mysql_table = "news";
?>
 
Ето: (позволих си малко да ти променя кода за да е по-лесно страницирането!) :wink:
Код:
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1251" />
<?php
 include("include/db.php");
            $query = mysql_query("SELECT * FROM $mysql_table");
            $query = mysql_query("SELECT * FROM `$mysql_table` ORDER BY `id` DESC LIMIT 0 , 25");
            if(mysql_error()) {
            print(mysql_error());
            }
			
// Странициране 1	

	$num = mysql_num_rows($query);

	$rowperpage = 6;
		
	$page = $_GET['page'];

	if (empty($page))
		$page = 0;
	
$plus = $page + 1;
$minus = $page - 1;

$min = $page * $rowperpage;
$max = ($page * $rowperpage) + $rowperpage;

$maxpage = $num / $rowperpage;
// Край на странициране 1

	for ($i = $min; $i < $max && $i < $num; $i++){

$title = mysql_result($query, $i, "title");
$text = mysql_result($query, $i, "content");

         echo "<h1>".$title."</h1><div class='comment'> ";
         
         //BBCode-а почва оттук
         $text=preg_replace("/\[b\](.+?)\[\/b\]/s", '<b>$1</b>',$text);

         $text=preg_replace("/\[i\](.+?)\[\/i\]/s", '<i>$1</i>',$text);

         $text=preg_replace("/\[u\](.+?)\[\/u\]/s", '<u>$1</u>',$text);

         $text=preg_replace("/\[quote\](.+?)\[\/quote\]/s", '<p style="width:auto; border:dashed 1px #CCC"><img src="images/quote.gif" />$1</p>',$text);

         $text=preg_replace("/\[quote\=(.+?)](.+?)\[\/quote\]/s", '<p style="width:auto; border="0">$1 êàçà:</p><p class="quote">$2</p>',$text);

         $text=preg_replace("/\[url\](.+?)\[\/url\]/s", '<a href="$1">$1</a>',$text);

         $text=preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/s", '<a href="$1">$2</a>',$text);

         $text=preg_replace("/\[img\](.+?)\[\/img\]/s", '<img src="$1" alt="Зареждане на изборажението" />',$text);

         $text=preg_replace("/\[color\=(.+?)\](.+?)\[\/color\]/s", '<span style="color:$1">$2</span>',$text);

         $text=preg_replace("/\[size=([1-5])\]((\s|.)+?)\[\/size\]/i", '<font size=\\1>\\2</font>', $text);

         $text=preg_replace("/\[code\](.+?)\[\/code\]/s",'Код:<br /><p class="code">$1</p>',$text);
         
         //Емотиконки
         $text=str_replace(":D",'<img src="smilies/biggrin.gif" />',$text);
         $text=str_replace(":P",'<img src="smilies/tongue.gif" />',$text);
         $text=str_replace(":-)",'<img src="smilies/blush.gif" />',$text);
         $text=str_replace("o.0",'<img src="smilies/blink.gif" />',$text);
         $text=str_replace("^_^",'<img src="smilies/closedeyes.gif" />',$text);
         $text=str_replace(":cool:",'<img src="smilies/cool.gif" />',$text);
         $text=str_replace(":pf:",'<img src="smilies/dry.gif" />',$text);
         $text=str_replace(":o",'<img src="smilies/ohmy.gif" />',$text);
         $text=str_replace(":)",'<img src="smilies/smile.gif" />',$text);
         $text=str_replace(":!:",'<img src="smilies/excl.gif" />',$text);
         $text=str_replace(":happy:",'<img src="smilies/happy.gif" />',$text);
         $text=str_replace(":huh:",'<img src="smilies/huh.gif" />',$text);
         $text=str_replace(":xaxa:",'<img src="smilies/laugh.gif" />',$text);
         $text=str_replace(":mad:",'<img src="smilies/mad.gif" />',$text);
         $text=str_replace(":^^:",'<img src="smilies/rolleyes.gif" />',$text);
         $text=str_replace(":(",'<img src="smilies/sad.gif" />',$text);
         $text=str_replace(":sleep:",'<img src="smilies/sleep.gif" />',$text);
         $text=str_replace(":hmm:",'<img src="smilies/unsure.gif" />',$text);
         $text=str_replace(":crazy:",'<img src="smilies/wacko.gif" />',$text);
         $text=str_replace(";)",'<img src="smilies/wink.gif" />',$text);
         
         $text = nl2br($text);

         echo "$text </p></div>";
       }
// Странициране БУТОНИ
	if (!($page <= 0)){
	echo "<a href=\"?page=".$minus."\"><< предишна | </a>";
}


$b = 1;
for ($a = 0; $a < $maxpage; $a++){
	if ($a == $page)
	echo "<a href=\"?page=".$a."\"><b> ".$b." </b></a>";
	
	else
	echo "<a href=\"?page=".$a."\"> ".$b." </a>";
	$b++;
}

if (($page + 1) < $maxpage)
	echo "<a href=\"?page=".$plus."\"> | следваща >></a>";

?>
 

Back
Горе