0

I am new to writing server code, anyway I have a SQL DB that contains a list of numbers, I am wanting to check to see if an array that contains a list of numbers has any overlap with the DB.

Database:
ID  Number
1    3
2    5
3    7
4    11
5    13
6    19

For example, in PHP/psuedocode:

$numbers = $_REQUEST['NUMBERS']  // array of numbers i.e. [3, 7, 20, 54]

This is what I'm looking for:

echo json_encode($result) // returns [3, 7]

1 Answer 1

1

Just do a query selecting the rows containing the numbers from the request:

$numbers = implode(',', $_REQUEST['NUMBERS']);
$query = "SELECT Number FROM TableName WHERE Number IN ($numbers)";
Sign up to request clarification or add additional context in comments.

Comments

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.