I have the following SQL Command:
$sql = "SELECT TOP 1
FROM products
ORDER BY ABS( price - '$price' ) ASC LIMIT 1";
$result = $conn->query($sql);
while($row = $result->fetch_array()){
echo "\r\n";
echo $row['price'];
echo "\r\n";
}
What I want to do is to find the closest number in column "price" to local variable $price. For example when user input price is 15000 I want to find closest number to this in the "price" column of the products table. Unfortunatly that gives me this problem:
PHP Fatal error: Uncaught Error: Call to a member function fetch_array() on bool in C:\Users\rojto\Documents\clones\Techalo\techalo-improvements\database.php:25
Stack trace:
#0 {main}
Can someone help me please?