Here's what the full query looks like:
PHP Code:
$uniq_banners = 3;
$query = 'SELECT '.$uniq_banners.' = COUNT(*) FROM (
SELECT DISTINCT 1 FROM banners WHERE sponsor LIKE "$sponsor" AND keyword LIKE "horizontal"
UNION ALL
SELECT DISTINCT 1 FROM banners WHERE sponsor LIKE "$sponsor" AND keyword LIKE "vertical"
UNION ALL
SELECT DISTINCT 1 FROM banners WHERE sponsor LIKE "$sponsor" AND (keyword LIKE "small" OR keyword LIKE "button")
) AS tbl';
$result = mysql_query("SELECT DISTINCT sponsor FROM table");
$myrow = mysql_fetch_array($result);
if ($myrow and @mysql_num_rows($result)) {
do {
$sponsor = $myrow["sponsor"];
eval("\$use_query = \"$query\";");
$result2 = mysql_query($use_query);
$res = mysql_result($result2, 0);
if ($res == 1)
// We got a sponsor that has the correct banners
;
} while($myrow = mysql_fetch_array($result));
}