I have a query that checks if the value exists in my table. then it stores the result in an array and outputs it in JSON. But my response is always : [{"SELECT EXISTS(SELECT * FROM wp_woocommerce_order_items WHERE order_id = $sdata)":"1"}; I just want to have it output the result (0 or 1 ) here is my code:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT EXISTS(SELECT * FROM wp_woocommerce_order_items WHERE order_id = $sdata)";
if ($result = mysqli_query($conn, $query)) {
$newArr = array();
/* fetch associative array */
while ($db_field = mysqli_fetch_assoc($result)) {
$newArr[] = $db_field;
}
echo json_encode($newArr); // get all products in json format.
}
$conn->close();
?>