<?php

include "../db.php";



if (isset($_POST['query']) && isset($_POST['type'])) {

    $query = $_POST['query'];

    $type = $_POST['type'];

    $recycle_condition = $type === 'active' ? '1' : '0';



    $sql = "SELECT * FROM data WHERE data_catagory = 'serviceDocument' AND data_recycle = '$recycle_condition' AND data_title LIKE '%$query%' ORDER BY data_sl_no DESC";

    $run = mysqli_query($con, $sql);

    $c = 1;

    while ($rows = mysqli_fetch_assoc($run)) {

        echo "

        <tr id='$rows[data_sl_no]'>

            <td class='align-middle'>

                <span class='text-dark '>$c</span>

            </td>

            <td class='align-middle'>

                $rows[data_title]

            </td>

            <td class='align-middle text-center' style='max-width:77px;'>

                <a class='btn btn-primary' style='margin-left:5px;' href='news.php?edit_id={$rows['data_sl_no']}'>Edit</a>

                <a href='news.php?rec_id={$rows['data_sl_no']}' class='delete m-2 btn btn-danger btn-sm rounded-circle' title='Click to Recycle'>

                    <i class='fa fa-recycle' aria-hidden='true'></i>

                </a>

            </td>

        </tr>";

        $c++;

    }

}

?>