Php: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(→API) |
||
Line 18: | Line 18: | ||
== API == | == API == | ||
web [[API]] | web [[API]] | ||
<?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 | |||
$data = array(); | |||
// Loop through the result set and add each row to the 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'] | |||
); | |||
} | |||
// Convert the array to JSON | |||
$json_data = json_encode($data); | |||
// Display the JSON data | |||
echo $json_data; | |||
?> |
Revision as of 05:53, 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'; // 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 $data = array();
// Loop through the result set and add each row to the 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'] );
}
// Convert the array to JSON $json_data = json_encode($data);
// Display the JSON data echo $json_data;
?>