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()*/
?>
showdev
  • 28,454
  • 37
  • 55
  • 73
conan
  • 1,327
  • 1
  • 12
  • 27

1 Answers1

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.

Punkfluff
  • 11
  • 2