0

I am trying to input an array into my query. I am using Wordpress.
For security purposes, I need to use %s.

If I don't use %s, and put the $results directly inside the query, it works.
But if I use %s, it doesn't work.

What am I doing wrong?

<?php
/*$sym_result is an array*/

$result = implode("','",$sym_result); 
$results = "'".$result."'";

$sql = $wpdb->get_results( $wpdb->prepare("
    SELECT DISTINCT fruit FROM dis WHERE fruit IN (%s)
            ",$results));
print_r($sql);/*echo array()*/
?>
1

1 Answer 1

1

Try this for your SQL statement:

SELECT DISTINCT fruit FROM dis WHERE fruit IN ("%s", "$results")

It's unclear from your question if you are wanting to use "%s" in lieu of "$results" or in addition? Either way it's the inverted commas that could be the issue I reckon.

Otherwise have you tried LIKE xxx OR xxx instead of IN? I have a feeling IN doesn't allow wildcards.

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.