Paging без МySQL

m3

Registered
Здравейте!
Как да сложа странициране на търсачка която не използва МYSQL а текстов файл(db.inc) за база данни.

Код:
<FORM ACTION="search.php" METHOD=POST> 
<INPUT TYPE="text" NAME="search" value="" size="35"> 
<INPUT TYPE=submit value=Search > 
</FORM> 


  
$search=$HTTP_POST_VARS['search']; 


$search=str_replace(" ","",$search); 
if ($search=='') 
{exit;} 
$file= file("db.inc"); 
$n=count($file); 
echo '<a> 
'; 

for ($i=0; $i<$n;$i++) 
{ 

$file1=$file[$i]; 
$file1=str_replace(" ","",$file1); 
$file1=str_replace("&","",$file1); 
$file1=str_replace("\n","",$file1); 

if (eregi($search,$file1)) 
{ 
$line = explode ("&",$file[$i] ); 
echo ' 
<p> 
<tr> 
<td>'.$line[0].'</td><td>'.$line[1].'</td><td>'.$line[2].'</td><td>'.$line[3].'</td> 
<td>'.$line[4].'</td><td>'.$line[5].'</td> 
</tr>'; 
} 
} 

?>

Thank`s
 

PhrozenCrew

Registered
Ето така се прави.

Код:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>asd</title>
</head>

<body bgcolor=#eaeaea>

<FORM ACTION="search1.php" METHOD="GET">
<INPUT TYPE="text" NAME="search" value="" size="35">
<INPUT TYPE=submit value=Search >
</FORM>
<?php 
$search=$_GET['search'];


$search=str_replace(" ","",$search);
if ($search=='')
{exit;}
$file= file("db.inc");
$n=count($file);
echo '<table border=1><tr><td>Име</td><td>Фамилия</td><td>ПОЩА</td><td>Телефон</td><td>Мобилен</td><td>Адрес</td></tr>';

for ($i=0; $i<$n;$i++){

$file1=$file[$i];
$file1=str_replace(" ","",$file1);
$file1=str_replace("&","",$file1);
$file1=str_replace("\n","",$file1);

	if (eregi($search,$file1)){
		$masiv[] = $file[$i];
	}
}

// OT TUK ZAPO4WA MOIA KOD
$text = '&search='.$search;
$itemPerPage = 5; //Колко елемента искаш да се показват на всяка страница
$total_pages = ceil(count($masiv)/$itemPerPage);
$current_page = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1; //страницата на която си в момента
$show_pages = 10; //колко страници искаш да се показват

$ot_elem = ($itemPerPage*$current_page) - $itemPerPage;
$do_elem = ($itemPerPage*$current_page) - 1;

for($x=$ot_elem; $x<=$do_elem; $x++){
	if ($masiv[$x] == '') continue;
	$line = explode ("&",$masiv[$x] );
	echo '
	<tr>
	<td>'.$line[0].'</td><td>'.$line[1].'</td><td>'.$line[2].'</td><td>'.$line[3].'</td>
	<td>'.$line[4].'</td><td>'.$line[5].'</td>
	</tr>';	
}
echo '</tr></table><br>';
paginlink($total_pages, $current_page, $show_pages, $text);

function paginlink($total_pages, $current_page, $show_pages, $text){	
	$self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
	$start_page = $current_page - floor($show_pages/2);
	$end_page = $current_page + floor($show_pages/2);
	if ($start_page <= 0) { $start_page = 1; }
	if ($end_page > $total_pages) { $end_page = $total_pages; }

	for ($i = $start_page;$i <= $end_page;$i++) {
		if ($i == $current_page) echo $i." ";
		else echo "<a href=\"$self?pageNum=$i$text\">$i</a> ";
	}
}
?>
Ако имаш проблеми пиши тук. Ще се опитам да ти помогна.
Успех!
 

Горе