  <?php require_once('../Connections/BE2.php'); ?>
<?php
 
$currentPage = "kind_add.html";//$_SERVER["PHP_SELF"];  
$maxRows_Rt2 = 20;
$pageNum_Rt2 = 0;
if (isset($_GET['pageNum_Rt2'])) {
  $pageNum_Rt2 = $_GET['pageNum_Rt2'];
}
$startRow_Rt2 = $pageNum_Rt2 * $maxRows_Rt2;
 
 
  
$colname_Rt2 = "-1";
if (isset( $_SESSION['login_memid']  )) {
  $colname_Rt2 =  $_SESSION['login_memid']  ;
}

$colname_Rt2=3;
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM product_kind WHERE company_num= '%s' ORDER BY kid DESC",$colname_Rt2);
$query_limit_Rt2 = sprintf("%s LIMIT %d, %d", $query_Rt2, $startRow_Rt2, $maxRows_Rt2);
$Rt2 = mysql_query($query_limit_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);

if (isset($_GET['totalRows_Rt2'])) {
  $totalRows_Rt2 = $_GET['totalRows_Rt2'];
} else {
  $all_Rt2 = mysql_query($query_Rt2);
  $totalRows_Rt2 = mysql_num_rows($all_Rt2);
}
$totalPages_Rt2 = ceil($totalRows_Rt2/$maxRows_Rt2)-1;


$queryString_Rt2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rt2") == false && 
	//   stristr($param, "act") == false && 
        stristr($param, "totalRows_Rt2") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rt2 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rt2 = sprintf("&totalRows_Rt2=%d%s", $totalRows_Rt2, $queryString_Rt2);
?> 
					    
 <div class="main "> 
 
 <div class="row">
 <div class="col-lg-12">				    
<a href="kindgoadd.html" style="cursor: pointer" ><b><font color="blue">產品分類資訊</font></b></a></p>
<a href="kindgoadd.html" class="btn btn-3d btn-red btn-md" target="_blank">新增產品分類</a>




<table class="table table-bordered table-striped table-condensed table-hover" style="min-width:200px;">
	<thead>
		<tr>
			<th width="30">ID</th>
			<th width="299">說明</th>
			<th width="56">管理</th>
		</tr>
	</thead>
	<tbody>
  <? if($totalRows_Rt2>0){ ?>  
  <?php do {   ?>
  <tr>
    <td><?= $row_Rt2['kid'];?></td>
    <td><?= $row_Rt2['kdoc'];?></td>
    <td align="center"><a href="editkind.html?kid=-<?= $row_Rt2['kid']; ?>" target="_self"><img src="../icon/edit.jpg" width="30" height="30" /></a></td>
  </tr>
    <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2));
      }
	?>
    <tbody>
</table>
 </div>
 <ul class="pagination">
                    <?   
                     if( $totalPages_Rt2 >1){	 
						    //分頁程式
if($totalPages_Rt2<5){
		 $start=0;
		 $end=$totalPages_Rt2;
		}else{  
	    $start=$pageNum_Rt2-5;
		$end=$pageNum_Rt2+5;
        if ($start<0){
		 $start=0;
		 $end=10; } 
		 else { $end=$start+10 ;}
		 if ($end>$totalPages_Rt2){ 
		   $start = $end-$totalPages_Rt2-5;
		   $end=$totalPages_Rt2;
		   }
		 if ($end-$start>10){ 
		   $start = $end-10;
		   }  
		 } ?> 
                     <?php if ($pageNum_Rt2 > 0) { // Show if not first page ?>
                     <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, max(0, $pageNum_Rt2 - 1), $queryString_Rt2); ?>">上一頁</a></li><?php } // Show if not first page ?>
                    	<?	   
		for($i=$start;$i<=$end;$i++){
		if($i==$pageNum_Rt2){ echo '<li class="active"><a href="#">'.($i+1).'</a></li>';} else {?>
            <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $i), $queryString_Rt2); ?>"><? echo $i+1 ;?></a></li>
                 
                        <?	}   }  ?>

                      <?php if ($pageNum_Rt2 < $totalPages_Rt2) { // Show if not last page ?>
                          <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $pageNum_Rt2 + 1), $queryString_Rt2); ?>">下一頁</a></li>
                        <?php }  
						             } ?>
								
						  </ul>
                          
                        
   </div> 
		</div>
<?php
mysql_free_result($Rt2);
  
?>        
        
 