| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/icd/msc/android/ |
Upload File : |
<?php
ini_set('html_errors', 0);
$DB_SERVER = "127.0.0.1";
$DB_USER = "icdmsc";
$DB_PASS = "icd2012msc";
$DB_DATABASE = "icdmscdb";
//Inform the recipient that the content is JSON
header('Content-Type: application/json');
//List of Genres, must be the same as the one in Android
$genres = array("all", "Science Fiction", "Fiction");
//var_dump($genres);
//Get all the filters from the URL
$filterTitle = (array_key_exists("title", $_GET)) ? $_GET["title"] : "";
$filterAuthor = (array_key_exists("author", $_GET)) ? $_GET["author"] : "";
$filterGenreId = (array_key_exists("genreid", $_GET)) ? $_GET["genreid"] : "";
//Print the filters
//var_dump($filterTitle);
//var_dump($filterAuthor);
//var_dump($filterGenreId);
//Add a condition in a SQL where string
function addWhereString($wherestr, $condition){
if (strlen($wherestr) > 0) $wherestr .= " AND ";
$wherestr .= $condition;
return $wherestr;
}
//Start building our SQL Query
$query = "SELECT * FROM `mscproject_books`";
$wherestr = "";
if ($filterTitle){
$wherestr = addWhereString($wherestr, "`title` LIKE '%$filterTitle%'");
}
if ($filterAuthor){
$wherestr = addWhereString($wherestr, "`author` LIKE '%$filterAuthor%'");
}
if ($filterGenreId){
$wherestr = addWhereString($wherestr, "`genreid` = $filterGenreId");
}
//Add the where string in our base query
if (strlen($wherestr) > 0){
$query .= " WHERE $wherestr";
}
//var_dump($query);
$res = new StdClass();
$res->Books = array();
//Connect to the Database
$dblink = mysqli_connect($DB_SERVER, $DB_USER, $DB_PASS, $DB_DATABASE);
//mysql_select_db($DB_DATABASE, $dblink);
//var_dump($dblink);
$rows=mysqli_query($dblink, $query);
while ($row = mysqli_fetch_object($rows)){
$res->Books[] = $row;
}
//Close the connection to the database
mysqli_close($dblink);
echo json_encode($res, JSON_PRETTY_PRINT);
//var_dump($res);
?>