include 'config_file.php'; $message = ''; $bool = 'false'; $connection = new mysqli($host_name, $host_user, $host_password, $database_name); if ($connection->connect_error) { die("Connection failed: " . $connection->connect_error); } $json = json_decode(file_get_contents('php://input'), true); $query = "SELECT * FROM Default_You_Are_Table ORDER BY RAND() LIMIT 1000"; $firstResult = mysqli_query($connection, $query); $check_query = "SELECT * FROM notification_quotes_table WHERE category IS NULL"; $result = mysqli_query($connection, $check_query); $a = array(); $finalArray = array(); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { array_push($a, $row["quotes"]); } $bool='true'; } if (mysqli_num_rows($firstResult) > 0) { while ($row1 = mysqli_fetch_assoc($firstResult)) { if ($bool == 'false') { array_push($finalArray, ["id"=>$row1["id"], "you_are"=>$row1["you_are"], "selected"=>"0"]); } else if (in_array($row1["you_are"], $a)) { array_push($finalArray, ["id"=>$row1["id"], "you_are"=>$row1["you_are"], "selected"=>"1"]); } else { array_push($finalArray, ["id"=>$row1["id"], "you_are"=>$row1["you_are"], "selected"=>"0"]); } } } else{ $message= "Error2"; echo json_encode($message); $connection->close(); } echo json_encode($finalArray); $connection->close(); ?>