
Code: Alles auswählen
$sql = "SELECT t.topic_id
FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p, " . VOTE_DESC_TABLE . " v
WHERE (t.topic_vote = 0
AND t.topic_status < 2
AND t.topic_last_post_id = p.post_id
AND p.post_time < $archive_topics_older_than)
OR (t.topic_vote = 1
AND t.topic_status < 2
AND t.topic_last_post_id = p.post_id
AND p.post_time < $archive_topics_older_than
AND t.topic_id = v.topic_id
AND v.vote_start+v.vote_length < " . time() . ")";
a.) ...älter als z.B. 90 Tage sind und keine Umfrage besitzen und
b.) ...älter als z.B. 90 Tage sind und eine Umfrage besitzen, die bereits abgelaufen ist
(unbegrenzt lange gehende Umfragen sind hier nicht berücksichtigt)
Verarbeitet wird das dann durch eine while- und for-Schleife, die problemlos funktioniert. Der obige Schnippsel tuts auch, was er soll, nur gibt er mir die entsprechenden Themen doppelt aus. Sprich habe ich die Themen 1,2,3 und Thema 3 ist eine zeitlich begrenzte Umfrage, dann verarbeitet die for-Schleife die topic_id's in dieser Reihenfolge: 1,2,1,2,3.
Ich habe überlegt, ob ich das OR vielleicht falsch angewendet habe. Daher habe ich die sql-Abfrage mal auf folgendes reduziert:
Code: Alles auswählen
$sql = "SELECT t.topic_id
FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p, " . VOTE_DESC_TABLE . " v
WHERE t.topic_vote = 0
AND t.topic_status < 2
AND t.topic_last_post_id = p.post_id
AND p.post_time < $archive_topics_older_than";
Danke schonmal, SemiX

EDIT: Auf den Rat von cYbercOsmOnauT hin Klammern eingefügt...