<?php
header("Content-Type: application/xml; charset=utf-8");

require 'config.php';

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// หน้า index
echo '<url><loc>https://smileherb.shop/</loc></url>';
echo '<url><loc>https://smileherb.shop/category.php</loc></url>';

// หมวดหมู่หลัก
echo '<url><loc>https://smileherb.shop/category.php?category=vabiz</loc></url>';
echo '<url><loc>https://smileherb.shop/category.php?category=ke</loc></url>';

// สินค้า
$sql = "SELECT id FROM products WHERE stock_quantity > 0";
$stmt = sqlsrv_query($conn, $sql);
if ($stmt) {
    while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
        $id = $row['id'];
        echo "<url><loc>https://smileherb.shop/product_detail.php?id={$id}</loc></url>";
    }
    sqlsrv_free_stmt($stmt);
}

// ปิด urlset
echo '</urlset>';
