Reputation: 91
I need a search query. Age value 10 - 15 , 20 - 25 , 17 - 19 , 12 - 59 , 2 - 19 , 18 - 40 , 10 - 20
I send 10 - 25 and I want to get results by matching the numbers
<?php
$Age1 = 10;
$Age2 = 25;
$Age = $Age1." - ".$Age2;
$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age LIKE '%" . $Age . "%'");
?>
Thanks to All
Upvotes: 0
Views: 428
Reputation: 21620
I guess what you need is between operator. The between operator aims to select values within a given range. In your scenario, an age range. This operator is inclusive. This means that begin and end values are included.
<?php
$Age1 = 10;
$Age2 = 25;
$stmt = mysqli_query(
$con,
"SELECT * " .
"FROM job_post_p1 " .
"WHERE Age BETWEEN $Age1 AND $Age2"
);
Upvotes: 2
Reputation: 113
$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");
Upvotes: -1
Reputation: 563
You should use the BETWEEN operator, it selects values within a given range.
Example:
$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");
Upvotes: 2