belajar paging sederhana simple

===pelajari algoritma nya doeloe y


====start algorithm

1. buat deret data
2. buat mysql_num_rows hitung jumlah data
3. buat $a dibagi 5, krn ingin tmpil hanya 5 data
4. buat for untuk link purpose
5. style="text-decoration:none"
6. limit 0.5 untuk tampil hanya 5 saja
7. setting href sesuai page $b nya
8. buat
if($page=="" || $page=="1"){

}
9.algoritma
1. 0,5 ($page*5)-5
2.  5,5
3.  10,5
  else


====end algorithm


buat database dahulu ,,..

just copas below query



create database dulu, nama database nya paging

==start query

-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Aug 07, 2016 at 05:54 PM
-- Server version: 5.6.21
-- PHP Version: 5.6.3

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `paging`
--

-- --------------------------------------------------------

--
-- Table structure for table `paging`
--

CREATE TABLE IF NOT EXISTS `paging` (
`id` int(11) NOT NULL,
  `name` varchar(5) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `paging`
--

INSERT INTO `paging` (`id`, `name`) VALUES
(1, 'a'),
(2, 'b'),
(3, 'c'),
(4, 'd'),
(5, 'e'),
(6, 'f'),
(7, 'g'),
(8, 'h'),
(9, 'i'),
(10, 'j'),
(11, 'k'),
(12, 'l'),
(13, 'm'),
(14, 'n'),
(15, 'o'),
(16, 'p');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `paging`
--
ALTER TABLE `paging`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `paging`
--
ALTER TABLE `paging`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=17;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


==end query



===start php native paging simple native

<!DOCTYPE html>
<html>
<head>
<title>paging</title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("paging");

$page=$_GET['page'];
if($page=="" || $page=="1"){
$page1=0;
}
else{
$page1=($page*5)-5;
}


$res = mysql_query("SELECT * FROM paging limit $page1,5");
while($row = mysql_fetch_array($res)){
echo $row['id']." ".$row['name'];
echo "<br>";
}


//this is for counting number of page
$res1 = mysql_query("SELECT * FROM paging");
$cou = mysql_num_rows($res1);
//echo $cou;

$a=$cou/5;
//echo $a;
//echo ceil($a);
$a = ceil($a);
echo "<br>";echo "<br>";

for($b=1; $b<=$a;$b++){
?><a href="paging-simple-indie.php?page=<?php echo $b;?>" style="text-decoration:none"><?php echo $b." ";?></a> <?php
}

?>

</body>
</html>

===end php

===start php paging simple ci code


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Paging extends CI_controller{

public function index(){

$this->paging1();


}

public function paging1(){

$page=$_GET['page'];
if($page=="" || $page=="1"){
$page1=0;
}
else{
$page1=($page*5)-5;
}
$db_call = $this->load->database('pagginggg', TRUE);

$table = "paging";

$q = "SELECT * FROM $table limit $page1,5";

$qryObj = $db_call->query($q);
$qryBag = $qryObj->result_array();

foreach ($qryBag as  $value) {
# code...
echo $value['id'].' '.$value['name'];
echo '<br>';

}
echo "<br>";

$q1 = "SELECT * FROM paging";
$qryObj1 = $db_call->query($q1);
$a = $qryObj1->num_rows();
$a = ceil($a/5);
//echo $a;
for($b=1;$b<=$a;$b++){
   
     ?> <a href="#" onclick="pagpag('<?php echo $b?>')" style="text-decoration:none"><?php echo $b;?></a><?php

     /*
bisa pake antara 1, 2 dibawah :
1.    ?> <a href="#" onclick="pagpag('<?php echo $b?>')" style="text-decoration:none"><?php echo $b;?></a><?php

  2.    ?> <a href="paging?page=<?php echo $b?>"  style="text-decoration:none"><?php echo $b;?></a><?php
     */
}


echo "<script>
function pagpag(a){

//aa = 'paging/test';
//window.location = aa;
aa = 'paging'+'?page='+a;
window.location = aa;
}</script>";
}

public function test(){
echo"asdf";
die();
}
}
===end php native paging simple ci code
selamat mempelajari simple paging

0 Response to "belajar paging sederhana simple"

Posting Komentar