Php: Difference between revisions

From Server STB
Jump to navigation Jump to search
Line 19: Line 19:
web [[API]]
web [[API]]


<?php
  <?php
include 'lib.php';
  include 'lib.php';
// Fetch data from the database
$sql = "SELECT propinsi, kabupaten_kota, kecamatan, npsn, sekolah, alamat_jalan  FROM sekolah WHERE `propinsi` LIKE '%Jawa Timur%' AND `kabupaten_kota` LIKE '%sidoarjo>
$result = mysqli_query($koneksipendidikan, $sql);


// Create an empty array to store the data
  $sql = "SELECT propinsi, kabupaten_kota, kecamatan, npsn, sekolah, alamat_jalan  FROM sekolah WHERE `propinsi` LIKE '%Jawa Timur%' AND `kabupaten_kota` LIKE '%sidoarjo>
$data = array();
  $result = mysqli_query($koneksipendidikan, $sql);


// Loop through the result set and add each row to the array
  $data = array();
while ($absen = mysqli_fetch_array($result)) {
 
  while ($absen = mysqli_fetch_array($result)) {
     $data[] = array(
     $data[] = array(
         'propinsi' => $absen['propinsi'],
         'propinsi' => $absen['propinsi'],
Line 38: Line 36:
         'alamat_jalan' => $absen['alamat_jalan']
         'alamat_jalan' => $absen['alamat_jalan']
     );
     );
}
  }
 
  $json_data = json_encode($data);
// Convert the array to JSON
  echo $json_data;
$json_data = json_encode($data);
  ?>
 
// Display the JSON data
echo $json_data;
 
?>

Revision as of 05:54, 22 January 2024

PHP

  • Contoh menampilkan ip address server
 <?php
 $command = 'ip addr show eth0 | grep -oP "inet \K[\d.]*"';
 $ipaddr = shell_exec($command);
 $host = trim($ipaddr);
 echo $host;
 ?>
 <?php
 echo $_SERVER['SERVER_NAME'];
 echo $_SERVER['REQUEST_URI'];
 ?>

Koneksi

Database

API

web API

 <?php
 include 'lib.php';
 $sql = "SELECT propinsi, kabupaten_kota, kecamatan, npsn, sekolah, alamat_jalan  FROM sekolah WHERE `propinsi` LIKE '%Jawa Timur%' AND `kabupaten_kota` LIKE '%sidoarjo>
 $result = mysqli_query($koneksipendidikan, $sql);
 $data = array();
 while ($absen = mysqli_fetch_array($result)) {
   $data[] = array(
       'propinsi' => $absen['propinsi'],
       'kabupaten_kota' => $absen['kabupaten_kota'],
       'kecamatan' => $absen['kecamatan'],
       'npsn' => $absen['npsn'],
       'sekolah' => $absen['sekolah'],
       'alamat_jalan' => $absen['alamat_jalan']
   );
 }
 $json_data = json_encode($data);
 echo $json_data;
 ?>