SELECT
b.id as b_id,
b.maxhits as b_maxhits,
b.maxklik as b_maxkli,
b.maxviewsprday as b_maxviewsprday
FROM banner b
JOIN
bannerhits bl
ON
b.id = bl.bannerid
AND
bl.userid = '".$this->userid."'
JOIN
bannerhits blog
ON
b.id = blog.bannerid
JOIN
bannerklik bk
ON
b.id = bk.bannerid
WHERE
(
b.placement = '".$place."'
AND
b.usertype IN ('".$usertype."', '')
AND
b.userpostalcode LIKE ',".$postcode.",'
AND
(
b.userage LIKE ',".$ageYears.",'
OR
b.userage IS NULL
)
AND
b.maxviewsprday IS NULL
)
OR
b.remainingshow = '1'
GROUP BY
bl.id,
bk.id,
blog.id
HAVING
(b.maxhits > count(blog.id) OR b.maxhits = '0')
AND
(b.maxklik > count(bk.id) OR b.maxklik = '0')
AND
(b.maxviewsprday > count(bl.id) OR b.maxviewsprday = '0')
ORDER BY
b.remainingshow ASC
LIMIT
1
Some guys helped me out on this query.. But now the problem is, that it doesn't return any rows.. I have created this row:
id bannertitle bannersrc bannerurl placement usertype userage userpostalcode maxviewsprday maxhits maxklik activefrom activeuntil remainingshow dato
8 Hej "" "" 0 "" "" "" 0 0 0 0000-00-00 00:00:00 0000-00-00 00:00:00 1 0000-00-00 00:00:00