<?php
//include('Pagination.php');
session_start();

include('config/koneksi2.php');
/* $start = !empty($_POST['page'])?$_POST['page']:0;
$limit = 10;
    
    //Get the total number of rows
    $queryNum = mysql_query("SELECT COUNT(distinct(CONCAT(kode_ax,config_ax))) as postNum FROM bs_stok where tipe='BIKE'");
    $resultNum = mysql_fetch_array($queryNum);
    $rowCount = $resultNum['postNum'];
    
    //Initialize Pagination class and create object
    $pagConfig = array('baseURL'=>'getdata.php', 'totalRows'=>$rowCount, 'perPage'=>$limit, 'contentDiv'=>'content');
    $pagination =  new Pagination($pagConfig);
  
if(isset($_POST['page'])){
$sql=mysql_query("select * from bs_stok where tipe='BIKE' group by kode_ax,config_ax order by nama ASC LIMIT $start,$limit");
}
else
{*/
$item_per_page 		= 5;
if(isset($_POST["page"])){
		$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //filter number
		if(!is_numeric($page_number)){die('Invalid page number!');} //incase of invalid page number
	}else{
		$page_number = 1; //if there's no page number, set it to 1
	}
	
	$results = mysql_query("SELECT COUNT(*) as jumlah FROM bs_stok where tipe='BIKE'");
	$get_total_rows =mysql_fetch_array($results); //hold total records in variable
	//break records into pages
	$total_pages = ceil($get_total_rows[jumlah]/$item_per_page);
	
	//get starting position to fetch the records
	$page_position = (($page_number-1) * $item_per_page);
	
	$sql=mysql_query("select * from bs_stok where tipe='BIKE' order by nama ASC LIMIT $page_position, $item_per_page");

//}
while($row=mysql_fetch_array($sql))
{
?>
<div class="col-xs-6 col-md-2">
    <a href="#" class="thumbnail">
      <img src="photo/<?php echo "$row[photo] "; ?>" >
    </a>
	<div class="caption">
        <h3><?php echo "$row[nama] "; ?> <?php echo "$row[config_ax] "; ?> <?php echo "$row[size_ax] "; ?> <?php echo "$row[colour_ax] "; ?></h3>
		<!--<input type="text" name="qty" id="qty" value="1" />-->
        <p><a href="#" class="btn btn-primary" role="button" name="add" id="add" onclick="cart('<?php echo $row[id] ?>')">Beli</a></p>
      </div>
  </div>
   
<?php
}

	echo '<div align="center">';
	/* We call the pagination function here to generate Pagination link for us. 
	As you can see I have passed several parameters to the function. */
	echo paginate_function($item_per_page, $page_number, $get_total_rows[0], $total_pages);
	echo '</div>';
	 
 
 
      //  echo $pagination->createLinks(); 
	  
	   function paginate_function($item_per_page, $current_page, $total_records, $total_pages)
{
    $pagination = '';
    if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ //verify total pages and current page number
        $pagination .= '<ul class="pagination">';
        
        $right_links    = $current_page + 3; 
        $previous       = $current_page - 3; //previous link 
        $next           = $current_page + 1; //next link
        $first_link     = true; //boolean var to decide our first link
        
        if($current_page > 1){
			$previous_link = ($previous==0)? 1: $previous;
            $pagination .= '<li class="first"><a href="#" data-page="1" title="First">&laquo;</a></li>'; //first link
            $pagination .= '<li><a href="#" data-page="'.$previous_link.'" title="Previous">&lt;</a></li>'; //previous link
                for($i = ($current_page-2); $i < $current_page; $i++){ //Create left-hand side links
                    if($i > 0){
                        $pagination .= '<li><a href="#" data-page="'.$i.'" title="Page'.$i.'">'.$i.'</a></li>';
                    }
                }   
            $first_link = false; //set first link to false
        }
        
        if($first_link){ //if current active page is first link
            $pagination .= '<li class="first active">'.$current_page.'</li>';
        }elseif($current_page == $total_pages){ //if it's the last active link
            $pagination .= '<li class="last active">'.$current_page.'</li>';
        }else{ //regular current link
            $pagination .= '<li class="active">'.$current_page.'</li>';
        }
                
        for($i = $current_page+1; $i < $right_links ; $i++){ //create right-hand side links
            if($i<=$total_pages){
                $pagination .= '<li><a href="#" data-page="'.$i.'" title="Page '.$i.'">'.$i.'</a></li>';
            }
        }
        if($current_page < $total_pages){ 
				$next_link = ($i > $total_pages) ? $total_pages : $i;
                $pagination .= '<li><a href="#" data-page="'.$next_link.'" title="Next">&gt;</a></li>'; //next link
                $pagination .= '<li class="last"><a href="#" data-page="'.$total_pages.'" title="Last">&raquo;</a></li>'; //last link
        }
        
        $pagination .= '</ul>'; 
    }
    return $pagination; //return pagination links
}

?>
