Untitled
unknown
plain_text
a month ago
1.3 kB
3
Indexable
Never
<?php include '../connection.php'; $method = $_SERVER['REQUEST_METHOD']; function response_data($code,$msg,$data = null){ $res = [ 'code' ==> $code, 'msg' ==> $msg, ]; if($data !== null){ $res['data'] = $data; } echo json_encode([ 'code' => 200, 'msg' => 'get detail data student', 'data' => $row ]); } switch ($method) { case 'GET'; if(isset($_GET['id'])){ $id = $_GET['id']; $q = $_connect->query("SELECT * FROM data_mhs WHERE id = $id"); $row = $q->fetch_all(MYSQLI_ASSOC); if($row){ echo json_encode([ 'code' => 200, 'msg' => 'get detail data student', 'data' => $row ]); }else{ echo json_encode([ 'code' => 404, 'msg' => 'no data', ]); } }else{ $q = $_connect->query('select * from data_mhs;'); $row = $q -> fetch_all(MYSQLI_ASSOC); echo json_encode([ 'code' => 200, 'msg' => 'get data student', 'data' => $row ]); } break; default: # code... break; } ?>
Leave a Comment