1

I am Having one PHP array variable called as

for($i=0;$i<sizeof($PhotoCatIdArray);$i++){
        $msg[$i]=$PhotoCatIdArray[$i];
}

The above array having int value like 1,3,5 which i would like to place in mysql SQL query .

SELECT * FROM photoCategories WHERE `ID` NOT IN ('1','3','5') 

I am trying place those array values in the query Not In ('1','3','5') condition. How i can place it , any one have idea to do it !

3 Answers 3

3

You can Use implode function:

PHP implode

$msgArr=implode(',',$msg);

$query="SELECT * FROM photoCategories WHERE `ID` NOT IN ($msgArr)"; 
Sign up to request clarification or add additional context in comments.

Comments

1
for($i=0;$i<sizeof($PhotoCatIdArray);$i++){
        $msg[$i]=$PhotoCatIdArray[$i];
}

//for details about implode function, http://php.net/manual/en/function.implode.php
$str=implode(',',$msg);

$query="SELECT * FROM photoCategories WHERE `ID` NOT IN ($str)"; 

Comments

1
$query = "SELECT * FROM photoCategories WHERE `ID` NOT IN (".join(",",$msg).")";

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.