There is a table:
articles. id | author | title | content | type 1 | author1, author2 | thetitle1 | text1 | typeA 2 | author1 | thetitle2 | text2 | typeB 3 | author2 | thetitle3 | text3 | typeA Arrays come from the client, they are like data filters:
$conditions = array(); $where = ''; if(isset($_POST['authors'])){ //empty, is_array and etc. $authors = $_POST['authors']; // [ author1, author2 ] $conditions[] = "author IN ('".implode("','",$authors)."')"; } if(isset($_POST['types'])){ $types = $_POST['types']; // [ typeA, typeB ] $conditions[] = "type IN ('".implode("','",$types)."')"; } if(!empty($conditions)){ $where = ' WHERE '.implode(' AND ', $conditions); } $sql = "SELECT * FROM articles".$where; Everything would be fine, but here only the author field can contain authors separated by commas, as can be seen from the example, which does not fall under such a filter: author IN ('author1') - naturally, such a filter will select only the 2nd entry from the table, but all records where this author participated (and this is the 1st and 2nd entries).