DEV Community

Eko Priyanto
Eko Priyanto

Posted on

Menampilkan data dari Supabase

Image description

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.";
}


Enter fullscreen mode Exit fullscreen mode

Top comments (0)