0

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

3
  • Can you add the sample data for job_post_p1 table? Commented Jun 6, 2017 at 19:58
  • You want to grab rows that have an age in between those two ages? tutorialspoint.com/mysql/mysql-between-clause.htm Commented Jun 6, 2017 at 19:59
  • We cannot provide the correct answer unless you provide the sample record in table for age Commented Jun 6, 2017 at 20:03

3 Answers 3

2

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");
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it selects the values where the age is between 10 - 25
2

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"
);

Comments

-1

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

2 Comments

You should explain why your answer is the correct one, why it should be used. You just posting the code saying "this is it" doesn't answer the question of why that's right, how can anyone else learn from it?
Thanks for advice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.