blaman blaman - 11 months ago 69
MySQL Question

php mysql counter doesn't work

I made a counter for genres, all works fine but there is one problem.

There are 2 different types. I only want the count from 1 type and not from both.
type 1 = movie
type 2 = tvshow

$genre_list = array('Action','Adult','Adventure','Animation','Biography','Bollywood','Comedy','Crime','Documentary','Drama','Family','Fantasy','History','Horror','Musical','Mystery','Reality-TV','Sci-Fi','Sport','Thriller','War','Western');
$query_parts = array();
foreach ($genre_list as $genre) {
$query_parts[] = "'%".mysql_real_escape_string($genre)."%'";

$string = implode(' OR genre LIKE ', $query_parts);
$tank = mysql_query("SELECT genre FROM `topmovies`.`movies` WHERE type='tvshow' AND genre LIKE {$string} GROUP BY name");

while( $fetch = mysql_fetch_array( $tank ) ){

$count = explode(', ', $fetch['genre']);

foreach( $count as $w)
if( in_array($w, $genre_list) )


As you see I want to count all genres from titles with the type 'tvshow', but the problem is, that it counts the genres from the type 'movie' too!

I really don't get what is wrong..


change AND genre LIKE {$string} to AND (genre LIKE {$string})

current query forms like:

(type='tvshow' AND genre LIKE "a") OR genre like "b"** ....