MySQLi BETWEEN is used to retrieve values within a range in a SELECT, INSERT, UPDATE, or DELETE statement.
Below the syntax of BETWEEN condition.
expression BETWEEN value1 AND value2 ;
MySQLi BETWEEN is used to retrieve values within a range in a SELECT, INSERT, UPDATE, or DELETE statement.
Below the syntax of BETWEEN condition.
expression BETWEEN value1 AND value2 ;
<?php
$conn = mysqli_connect('localhost:3306', 'user_name', 'password', 'db_nexladder');
if(! $conn) {
die('Could not connect: ' . mysqli_error());
}
$sql = "SELECT `first_name` FROM `tbl_customers` WHERE `id` BETWEEN 3 AND 7";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_object($result)) {
echo "Name: " . $row->first_name. "<br />";
}
} else {
echo "0 rows";
}
mysqli_close($conn);
?>
Parameters:
expression: A column or calculation.
value1 and value2: These values create an inclusive range that expression is compared to.
Note:The MySQLi BETWEEN Condition will return the records where expression is within the range of value1 and value2 (inclusive).
Below it'll look like: