Bagosep

Index-1

Jun 1st, 2021 (edited)
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. require 'vendor/autoload.php';
  2. use GuzzleHttp\Client;
  3.  
  4. if (isset($_POST['cari'])) {
  5.  
  6.     $client = new Client([
  7.         'base_uri' => 'https://api.deezer.com',
  8.     ]);
  9.    
  10.     $response = $client->request('GET', 'https://api.deezer.com/search/track?q='.$_POST['cari']);
  11.     $hasil = json_decode($response->getBody());
  12.     $_SESSION['cari'] = $_POST['cari'];
  13.     $_SESSION['total'] = $hasil->total;
  14.  
  15.  
  16. }
  17.  
  18. if(isset($_GET['page'])){
  19.     if($_GET['page'] == "0"){
  20.         $client = new Client([
  21.             'base_uri' => 'https://api.deezer.com',
  22.         ]);
  23.        
  24.         $response = $client->request('GET', 'https://api.deezer.com/search/track?q='.$_SESSION['cari']);
  25.         $hasil = json_decode($response->getBody());
  26.         $_SESSION['total'] = $hasil->total;
  27.     }elseif (!empty($_GET['page'])) {
  28.        
  29.         $client = new Client([
  30.             'base_uri' => 'https://api.deezer.com',
  31.         ]);
  32.        
  33.         $response = $client->request('GET', 'https://api.deezer.com/search/track?q='.$_SESSION['cari'].'&index='.$_GET['page']);
  34.         $hasil = json_decode($response->getBody());
  35.         $_SESSION['total'] = $hasil->total;
  36.        
  37.     }
  38.    
  39. }
  40.  
  41. if (!empty($_SESSION['total'])) {
  42.     $page = isset($_GET['page'])?(int)$_GET['page'] : 0;
  43.  
  44.     $previous = $page - 25;
  45.     $next = $page + 25;
  46.  
  47.     $total_page = $_SESSION['total'];
  48. }
Add Comment
Please, Sign In to add comment