0

I have one-dimensional-array $abc.

$abc = array (90, 91, 92, 93, 94, 95, 96, 97, 98, 99);

I want to use it in WHERE IN

SELECT *
FROM table
WHERE columnA IN ()

while (){
$def[] = $row['def'];  
} 

When I use simple IN('$abc') I have a response - Undefined variable: def

How to do it properly?

3 Answers 3

2

You can use implode() function:

$abc = array (90, 91, 92, 93, 94, 95, 96, 97, 98, 99);
$str = implode(',', $abc);

Now you can use $str in IN clause.


Learn more about implode() function.

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

Comments

0

The implode make it easy for you

$query='SELECT *
FROM table
WHERE columnA IN ('.implode(',', $abc).')';

Comments

0

Try:


$abc = array (90, 91, 92, 93, 94, 95, 96, 97, 98, 99);
$imploded = implode(",", $abc);
//then your query
SELECT *
FROM table
WHERE columnA IN ($imploded)

Hope it helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.