<?php

require ('../credentials.php');
$con=mysqli_connect(HOST, USERNAME, PASSWORD, DBNAME)or die("cannot connect"); 

$by=$_POST['by'];
  $keyword=$_POST['keyword'];
//fetch table rows from mysql db
    $sql = "select title,description from news where $by like '%$keyword%'";
    $result = mysqli_query($con, $sql) or die("Error in Selecting " . mysqli_error($con));

//echo $sql;
    //create an array
    $emparray = array();
    while($row =mysqli_fetch_assoc($result))
    {
        $emparray[] = $row;
    }
    echo json_encode($emparray);

    //close the db connection
    mysqli_close($con);

?>
