Berikut script PHP untuk menampilkan data dari Supabase
<?php
$supabaseUrl = 'https://xxx.supabase.co';
$supabaseKey = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy';
$tableName = 'places'; // Ganti dengan nama tabel yang benar
$fields = 'name,reviews'; // Field yang ingin diambil
$limit = 10; // jumlah data
$url = "$supabaseUrl/rest/v1/$tableName?select=$fields&limit=$limit";
$headers = [
"apikey: $supabaseKey",
"Authorization: Bearer $supabaseKey",
"Content-Type: application/json"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data) {
foreach ($data as $row) {
echo "Name: " . htmlspecialchars($row['name']) . "<br>";
echo "Reviews: " . htmlspecialchars($row['reviews']) . "<br><hr>";
}
} else {
echo "No data found.";
}
Top comments (0)