0

Is it possible to assign php array in MySQL IN() function? for example,

$numbers = array('8001254656','8886953265','88864357445','80021536245');
$sql = mysql_query("SELECT * FROM `number_table` WHERE `number` IN ($numbers)");

Any Ideas?

Thanks,

2 Answers 2

4

This code snippet should help you out, as long as number is restricted to numbers.

<?php

// Generate a filtered comma-separated list of the numeric values in numbers.
// Non-numeric values might allow for SQL-injection bugs.
$SQL_numberList = implode(", ", array_filter($numbers, 'is_numeric'));
$sql = mysql_query("SELECT * FROM `number_table` WHERE `number` IN ($SQL_numberList)");

For string arguments in the list you'll need to do something a little different.

Sign up to request clarification or add additional context in comments.

Comments

1

No. Use implode() first.

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.