How can I use an array within a SQL query

Posted by ThinkingInBits on Stack Overflow See other posts from Stack Overflow or by ThinkingInBits
Published on 2010-05-18T07:51:25Z Indexed on 2010/05/18 8:00 UTC
Read the original article Hit count: 155

Filed under:
|
|
|

So I'm trying to take a search string (could be any number of words) and turn each value into a list to use in the following IN statement) in addition, I need a count of all these values to use with my having count filter

$search_array = explode(" ",$this->search_string);
$tag_count = count($search_array);

$db = Connect::connect();
$query = "select p.id
          from photographs p
          left join photograph_tags c
          on p.id = c.photograph_id
          and c.value IN ($search_array)
          group by p.id
          having count(c.value) >= $tag_count";

This currently returns no results, any ideas?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql