Poth Hara Pothik
Poth Hara Pothik

Reputation: 91

How to query search numbers in php mysql

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

Answers (3)

sensorario
sensorario

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

vivek gupta
vivek gupta

Reputation: 113

$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");

Upvotes: -1

Randy
Randy

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

Related Questions