分页和数据传递 [英] Pagination and Data Passing

查看:100
本文介绍了分页和数据传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个问题,我在其中有一个带有数据的表并进行一些分页,问题是,我无法在分页内的页面之间传递数据,例如,我有一个count函数,将显示10每页的数据,但是如果我转到下一页,计数将返回1,而不是11,请有人可以帮助我吗?这是帮助您更清楚地看到代码的代码:

代码:

I have a problem here, I have a table with data inside it and do some pagination, the problem is, I cant pass the data between the page inside pagination, for example, I have a count function, and will view 10 data per page, but the count will return back to 1 if I go to next page, instead of 11, please can somebody help me? here a the code to help you guys see more clearly :

Code:

<?php require_once('auth.php'); ???>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
#tengah 
{border:10px outset #0066FF;} 

#tepiatas 
{border:5px outset #0066FF;}

.paginate {
font-family:Arial, Helvetica, sans-serif;
	padding: 3px;
	margin: 3px;
}

.paginate a {
	padding:2px 5px 2px 5px;
	margin:2px;
	border:1px solid #999;
	text-decoration:none;
	color: #666;
}
.paginate a:hover, .paginate a:active {
	border: 1px solid #999;
	color: #000;
}
.paginate span.current {
    margin: 2px;
	padding: 2px 5px 2px 5px;
		border: 1px solid #999;
		
		font-weight: bold;
		background-color: #999;
		color: #FFF;
	}
	.paginate span.disabled {
		padding:2px 5px 2px 5px;
		margin:2px;
		border:1px solid #eee;
		color:#DDD;
	}
	
		
	ul{margin:6px;
	padding:0px;}	

</style>
<link rel="shortcut icon" href="quran.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>

</head>
<body bgcolor="white">
<table width="100%" border="1" align="center" bgcolor="white">
  <tr>
  <td id="tepiatas" height="140" colspan="3">
</td>
  </tr>
  <tr>
  
	
    <td id="tepiatas" width="15%" height="536" align="center" bgcolor="white">
	<?php include 'menu.php'; ???>
	</td>
	
    <!-- menu section -->
	
    <td id="tengah" width="85%" bgcolor="white">
	
	<h3><center>Senarai Kilang di Fasa 1</center>
	<br />
	<br />
	
include 'dbconnect.php';
$tableName="kilang_fasa1";		
	$targetpage = "fasa1add_view.php"; 	
	$limit = 10; 
	$count ='0';
	
	$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['page']);
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
		}	
	
    // Get page data
	$query1 = "SELECT * FROM $tableName LIMIT $start, $limit";
	$result = mysql_query($query1);
	
	// Initial page num setup
	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">";
		// Previous
		if ($page > 1){
			$paginate.= "<a href="$targetpage?page=$prev">previous</a>";
		}else{
			$paginate.= "<span class="disabled">previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up

		{	

			for ($counter = 1; $counter <= $lastpage; $counter++)

			{

				if ($counter == $page){

					$paginate.= "<span class="current">$counter</span>";
				}else{
					$paginate.= "<a href="$targetpage?page=$counter">$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			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?page=$counter">$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href="$targetpage?page=$LastPagem1">$LastPagem1</a>";
				$paginate.= "<a href="$targetpage?page=$lastpage">$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href="$targetpage?page=1">1</a>";
				$paginate.= "<a href="$targetpage?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?page=$counter">$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href="$targetpage?page=$LastPagem1">$LastPagem1</a>";
				$paginate.= "<a href="$targetpage?page=$lastpage">$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href="$targetpage?page=1">1</a>";
				$paginate.= "<a href="$targetpage?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?page=$counter">$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 

			$paginate.= "<a href="$targetpage?page=$next">next</a>";
		}else{
			$paginate.= "<span class="disabled">next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}
echo '<center>';
echo 'Sebanyak ' .$total_pages.' Kilang Ditemui';
echo '<br>';
echo '<br>';
 // pagination
 echo $paginate;
 echo '</br></br></center>';
 echo '<br>';
 echo '<br>';
'<ul>';		

echo '<center>';
echo '<table width="50%" border="1">';
echo '<tr>';
echo'<td width="5%" align="center">Bil</td>';
echo'<td width="5%" align="center">Nombor Fail</td>';
echo'<td width="10%" align="center">Kod Kilang</td>';
echo'<td width="25%" align="center">Nama Kilang</td>';
echo'<td width="5%" align="center">Data Penuh</td>';
echo'</tr>';


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
	 	$count = $count+1;
		echo '<tr>';
		echo '<td align="center">'.$count.'</td>';
		echo '<td align="center">'.$row['no_fail'].' </td>';
		echo '<td align="center">'.$row['kod_kilang'].' </td>';
		echo '<td align="center">'.$row['nama_kilang'].'</td>';
		?>
		<td align="center"><a href="fasa1add_viewmore.php?id=<?php echo $row['no_fail']; ?>">Semak</a></td>
				echo '</tr>';
		
	}
	
	echo '</table>';
	echo '<center>';
	echo '<br>';
 	echo '<br>';
	echo $paginate;
?>
</br></br></center></center></ul>
<br />
<br />
<br />
<a href="fasa1add.php">Tambah Data</a> ||
<a href="logout.php">Keluar</a>
	</br></br></h3></td>
	
   
  </tr>
  
</table>
</body>
</html>

推荐答案

tableName="kilang_fasa1";
tableName="kilang_fasa1";


targetpage = "fasa1add_view.php";
targetpage = "fasa1add_view.php";


limit = 10;
limit = 10;


这篇关于分页和数据传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆