📂 FileMgr
📍
C:\Inetpub\vhosts\doitcajmer.in\akhileshmittal.in/api
✏️ Edit File: C:\Inetpub\vhosts\doitcajmer.in\akhileshmittal.in/api/posts.php
⬅ Kembali
<?php header("Content-Type: application/json; charset=UTF-8"); header("Access-Control-Allow-Origin: *"); include("../config/db.php"); // Pagination $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page = max($page, 1); $limit = 10; $offset = ($page - 1) * $limit; // Search $search = isset($_GET['search']) ? trim(mysqli_real_escape_string($conn, $_GET['search'])) : ""; // Category $category = isset($_GET['category']) ? trim(mysqli_real_escape_string($conn, $_GET['category'])) : ""; $where = []; // Search in Title + Content if (!empty($search)) { $where[] = "(p.title LIKE '%$search%' OR p.content LIKE '%$search%')"; } // Category Filter if (!empty($category) && strtolower($category) != "all") { $where[] = "c.name = '$category'"; } $whereSql = ""; if (!empty($where)) { $whereSql = "WHERE " . implode(" AND ", $where); } // Total Posts $totalQuery = mysqli_query($conn, " SELECT COUNT(*) AS total FROM posts p LEFT JOIN categories c ON p.category_id = c.id $whereSql "); $totalRow = mysqli_fetch_assoc($totalQuery); $totalPosts = (int)$totalRow['total']; $totalPages = ceil($totalPosts / $limit); // Posts $sql = " SELECT p.id, p.title, p.image, p.created_at, p.reading_time, c.name AS category FROM posts p LEFT JOIN categories c ON p.category_id = c.id $whereSql ORDER BY p.created_at DESC LIMIT $limit OFFSET $offset "; $result = mysqli_query($conn, $sql); $data = []; while ($row = mysqli_fetch_assoc($result)) { $row['image'] = "https://www.akhileshmittal.in/uploads/" . rawurlencode($row['image']); $data[] = $row; } echo json_encode([ "status" => true, "current_page" => $page, "total_pages" => $totalPages, "total_posts" => $totalPosts, "posts" => $data ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
💾 Simpan File
Batal
⬅ Naik ke akhileshmittal.in
2 item
Nama
Tipe
Ukuran
Diubah
Aksi
🐘
post.php
php
1.2 KB
2026-07-08 17:29
✏️ Edit
👁️ View
🗑 Hapus
🐘
posts.php
php
1.9 KB
2026-07-14 14:39
✏️ Edit
👁️ View
🗑 Hapus