<?php

require_once "conn.php";

$stmt = $conn->prepare("SELECT a.id, a.gambar, a.isi, a.tgl_upload, a.id_user, u.nama AS nama_user, a.judul, a.hit 
                       FROM artikel AS a
                       JOIN user AS u ON a.id_user = u.id;");

$stmt->execute();
$stmt->bind_result($id, $gambar, $isi, $tgl_upload, $id_user, $nama_user, $judul, $hit);

$artikel = array();

while($stmt->fetch()){
    $temp = array();
    $temp['id'] = $id;
    $temp['gambar'] = $gambar;
    $temp['isi'] = $isi;
    $temp['tgl_upload'] = $tgl_upload;
    $temp['pembuat'] = $nama_user;
    $temp['judul'] = $judul;
    $temp['dilihat'] = $hit;

    array_push($artikel, $temp);
}

echo json_encode($artikel);
?>
