Възможно ли е странициране

feweR

Registered
Този код който не е с MySQL има ли някакъв начин да се страницира.
PHP:
<?php
for ($i=$broi; $i>$broi-4;$i--){
 if (is_file("posts/".$i.".html")) {
 include "posts/".$i.".html";
 echo "<BR />";
 
 }
}
?>
системата за новини която ползвам е http://web-tourist.net/login/login/view.php?st=775
 
PHP:
<?php

function page(){
      if(isset($_GET['page'])){
        $page = $_GET['page'];
	$g = chr(92);
        $page = str_replace($g , "", $_GET['page']);
        $page = str_replace("/" , "", $page);
 	$page = str_replace("-" , "", $page);
        $page = str_replace(";" , "", $page);
        $page = str_replace("'" , "", $page);
        $page = str_replace("%00" , "\0", $page);
        $page = str_replace("?" , "", $page);
	$page = str_replace("$" , "", $page);
        $page = htmlspecialchars($page);
      if (is_file("papkata s stranicite/".$page.".php")) {
      	    include("papkata s stranicite/".$page.".php");
	
      } else {	
              
		Echo ("<br>Страницата $page не съществува!<br>");
      }
   }
}
?>
:?
 
ен стана .... нищо не излиза и на мен ми трябва примерно новините са 15 общо искам да се показват само 5 и другите от доло да пише

1,2,3 и примерно като кликна на страница 2 и да ми показва другите 5 новини
 
така ?

index.php
Код:
<html>
<head>
<link rel="stylesheet" href="files/font.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Новини</title>
</head>
<body>
<center>
<table width="65%" align="center">
 <tr>
  <td>
<?php
   $page = 2; //брой на новини на странца
   $broi = 0; 
   $handle = opendir('posts/');
   while ($read_file = readdir($handle))
    {
        if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
        {
            $broi = $broi + 1;
        }
    }
   closedir($handle); 
   $pages=ceil($broi/$page); //пресмятаме колко ще са страниците
   $pg = (int)$_GET['page'];
   if($pg <= 0 || $pg == NULL || $pg>$pages)
    {
        $pg = 1;
    }
   else
    {
        $limit = ($pg-1)*$page;
		$limh = 0; $i = 0;
        $handle = opendir('posts/');
        while ($read_file = readdir($handle))
        {
            if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
			{
			    $limh = $limh + 1;
			    if($limit < $limh and $i<$page)
			    {
			        include "./posts/$read_file";
                    echo "<BR />"; 
					$i = $i + 1;
			    }
			}
        }
    }
if($pg <= $pages  and $pg != 1) 
{
 $prev = $pg - 1; 
 echo "<a href='index.php?page=$prev'>[Предишна]</a>";
}
elseif($pg == 1)
{
 echo "[Предишна]";
}

if($pg < $pages and $pg != $pages) 
{
 $next = $pg + 1; 
 echo "<a href='index.php?page=$next'>[Следваща]</a>";
}
elseif($pg == $pages)
{
 echo "[Следваща]";
}
?>
  </td>
 </tr>
</table>
</center>
</body>
</html>
 
ок този добре но когато линка не е с ?page=и номера на страницата не излизат новини ... S
 
Да. Не се сетих как да го направя. Днес по-късно ако имам време ще го направя.
 
аз го оправих :)

PHP:
 <html>
<head>
<link rel="stylesheet" href="files/font.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Новини</title>
</head>
<body>
<center>
<table width="65%" align="center">
 <tr>
  <td>
<?php
   $page = 2; //брой на новини на странца
   $broi = 0; 
   $handle = opendir('posts/');
   while ($read_file = readdir($handle))
    {
        if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
        {
            $broi = $broi + 1;
        }
    }
   closedir($handle); 
   $pages=ceil($broi/$page); //пресмятаме колко ще са страниците
   $pg = (int)$_GET['page'];
   if($pg <= 0 || $pg == NULL || $pg>$pages || !$pg || !isset($pg))
    {
        $pg = 1;
    }
   else
    {
        $limit = ($pg-1)*$page;
      $limh = 0; $i = 0;
        $handle = opendir('posts/');
        while ($read_file = readdir($handle))
        {
            if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
         {
             $limh = $limh + 1;
             if($limit < $limh and $i<$page)
             {
                 include "./posts/$read_file";
                    echo "<BR />"; 
               $i = $i + 1;
             }
         }
        }
    }
if($pg <= $pages  and $pg != 1) 
{
 $prev = $pg - 1; 
 echo "<a href='index.php?page=$prev'>[Предишна]</a>";
}
elseif($pg == 1)
{
 echo "[Предишна]";
}

if($pg < $pages and $pg != $pages) 
{
 $next = $pg + 1; 
 echo "<a href='index.php?page=$next'>[Следваща]</a>";
}
elseif($pg == $pages)
{
 echo "[Следваща]";
}
?>
  </td>
 </tr>
</table>
</center>
</body>
</html>
 
Горе само защитава, но пак не става. С идеята на @IzKuFeLiQqQqQ го направих долу. Сега вече трябва да работи.

PHP:
 <html>
<head>
<link rel="stylesheet" href="files/font.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Новини</title>
</head>
<body>
<center>
<table width="65%" align="center">
 <tr>
  <td>
<?php
   $page = 2; //брой на новини на странца
   $broi = 0; 
   $handle = opendir('posts/');
   while ($read_file = readdir($handle))
    {
        if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
        {
            $broi = $broi + 1;
        }
    }
   closedir($handle); 
   $pages=ceil($broi/$page); //пресмятаме колко ще са страниците
   $pg = (int)$_GET['page'];
   if(!$pg || !isset($pg))
   {
        $pg = 1; $n = 1;
		$handle = opendir('posts/');
        while ($read_file = readdir($handle))
		{
		    if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
			{
			    if($n<=$page)
				{
			        include "./posts/$read_file";
                    echo "<BR />";    		
                    $n = $n + 1;
                }					
			}
		}
   }
   else
   {
   if($pg <= 0 || $pg == NULL || $pg>$pages)
    {
        $pg = 1;
    }
   else
    {
        $limit = ($pg-1)*$page;
      $limh = 0; $i = 0;
        $handle = opendir('posts/');
        while ($read_file = readdir($handle))
        {
            if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
         {
             $limh = $limh + 1;
             if($limit < $limh and $i<$page)
             {
                 include "./posts/$read_file";
                    echo "<BR />"; 
               $i = $i + 1;
             }
         }
        }
    }
	}
if($pg <= $pages  and $pg != 1) 
{
 $prev = $pg - 1; 
 echo "<a href='index.php?page=$prev'>[Предишна]</a>";
}
elseif($pg == 1)
{
 echo "[Предишна]";
}

if($pg < $pages and $pg != $pages) 
{
 $next = $pg + 1; 
 echo "<a href='index.php?page=$next'>[Следваща]</a>";
}
elseif($pg == $pages)
{
 echo "[Следваща]";
}
?>
  </td>
 </tr>
</table>
</center>
</body>
</html>
 
дамз така излиза сичко имам въпрос ... как да нарпавя най-новата новина да е най-отпред ...
 
@akatsuki аз излизам използвай кода от тука http://web-tourist.net/forum/viewtopic.php?t=109776 (твоята тема xD) за да му сортираш файловете по дата ;)
 
Код:
 <html>
<head>
<link rel="stylesheet" href="files/font.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Новини</title>
</head>
<body>
<center>
<table width="65%" align="center">
 <tr>
  <td>
<?php
   $page = 2; //брой на новини на странца
   $broi = 0; 
   $handle = opendir('posts/');
   $arr = array();
   while ($read_file = readdir($handle))
    {
        if (!is_link($read_file) and $read_file != "." and $read_file != ".." and $read_file != "thumbs.db")
        {
            $broi = $broi + 1;
			$arr[$broi] = $read_file;
        
		}
    }
   rsort($arr);
   closedir($handle); 
   $pages=ceil($broi/$page); //пресмятаме колко ще са страниците
   $pg = (int)$_GET['page'];
   if(!$pg || !isset($pg))
   {
        $pg = 1; $n = 1;
        for($m = 0; $m<$broi; $m++)
		{
			    if($n<=$page)
				{
                    include "posts/$arr[$m]"; 
                    echo "<br />";					
                    $n = $n + 1;
                }					
		}
   }
   else
   {
   if($pg <= 0 || $pg == NULL || $pg>$pages)
    {
        $pg = 1;
    }
   else
    {
        $limit = ($pg-1)*$page;
        $limh = 0; $i = 0;
        for($m = 0; $m<$broi; $m++)    
        {
             $limh = $limh + 1;
             if($limit < $limh and $i<$page)
             {
                 include "posts/$arr[$m]";
                 echo "<BR />"; 
               $i = $i + 1;
             }
        }
    }
	}
if($pg <= $pages  and $pg != 1) 
{
 $prev = $pg - 1; 
 echo "<a href='index.php?page=$prev'>[Предишна]</a>";
}
elseif($pg == 1)
{
 echo "[Предишна]";
}

if($pg < $pages and $pg != $pages) 
{
 $next = $pg + 1; 
 echo "<a href='index.php?page=$next'>[Следваща]</a>";
}
elseif($pg == $pages)
{
 echo "[Следваща]";
}
?>
  </td>
 </tr>
</table>
</center>
</body>
</html>

Айде готов си.
 

Back
Горе