Advertisement
GWibisono

paging sederhana

Jul 22nd, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2. if(isset($_GET['show']))
  3. {
  4.     //=====ASUMSIKAN INI Adalah data dari id=1
  5.     $arrayData=array(
  6.     array('SIC Agito', 'SIC Another Agito', 'SIC Giils', 'SCM  Aries', 'SCM Harpy', 'Eagle Marin'),
  7.   array('Alvis & Lavie', 'Figma BRS', ' Nendo Max', 'Racing Miku','Luka'),
  8.   array('Kratos','Spartan IV','Spartan V', 'Master Chief','Ninja')
  9.  
  10.   );
  11.  
  12.     $hal=$_POST['hal']-1;
  13.   $show=$arrayData[$hal];
  14.   $s='';
  15.   foreach($show as $v)
  16.   {
  17.         $s.="\n<tr><td>$v</td><td>Rp. xxxxxx</td></tr>";
  18.   }
  19.   $a=array('table'=>$s);
  20.   $json=json_encode($a);
  21.     die($json);
  22. }
  23.  
  24.  
  25. ?><script src='js/jquery.js'></script>
  26. <script>
  27. jQuery(document).ready(function($){
  28.     jQuery.ajax({
  29.         url: "?show=1",
  30.         type: "POST",
  31.         dataType: "json",
  32.         data: "hal=1",
  33.         success: function(data){
  34.        $(".list").append(data.table);
  35.         }
  36.     });
  37. });
  38. </script>
  39. BARANG JUALAN SAYA
  40. <table class='list'>
  41.  
  42. </table>
  43. Klik angka untuk membuka halaman lain
  44. <?php
  45. for($i=1;$i<=3;$i++)
  46. {
  47.     echo "<a href=# class='viewPage' pos='$i'>$i</a> - ";
  48.  
  49. }
  50. ?>
  51. <script>
  52.  jQuery( "a.viewPage").click(function()
  53.  {
  54.      $('.viewPage').attr('href', '#');
  55.     $(this).removeAttr('href');
  56.              pos=jQuery(this).attr('pos');
  57.          $(".list").empty();
  58.              jQuery.ajax({
  59.                   url: "?show=1",
  60.                   type: "POST",
  61.                   dataType: "json",
  62.                   data:  "hal="+pos,
  63.                   success: function(data){
  64.                  $(".list").append(data.table);
  65.                   }
  66.               });
  67.         console.log('page '+pos);
  68.     });
  69. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement