sql-befehl für new posts

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/sql-befehl_fuer_new_posts_132521/page_1 - zur Vollversion wechseln!


tomstig schrieb am 20.12.2004 um 22:29

also, da ich grad das phpbb nach meinen wünschen formatier brauch ich folgendes:

genau das, was ihr auch auf der linken seite habt - das new posts...
so weit hab ich schon das:

Code: PHP
SELECT t.topic_title, u.username, p.post_time
FROM  `posts` p 
LEFT  JOIN topics t
USING ( topic_id ) LEFT JOIN users u ON u.user_id = p.poster_id 
ORDER  BY p.post_time DESC 
LIMIT 0 , 7

das einzige was mir noch fehlt, ist, dass immer nur ein topic_title geladen wird, also wenn die letzten 7 antworten in einem topic waren, sollen nicht nur diese angezeigt werden, sondern eben 7 verschiedene topics...

geht das überhaupt nur in mysql oder in php (stell ich mir grad noch unmöglicher vor)


murcielago schrieb am 20.12.2004 um 22:34

"select DISTINCT" und dann deins


tomstig schrieb am 20.12.2004 um 22:44

Code: PHP
SELECT DISTINCT t.topic_title, u.username, p.post_time
FROM `posts` p
LEFT JOIN topics t
USING ( topic_id )
LEFT JOIN users u ON u.user_id = p.poster_id
ORDER BY p.post_time DESC
LIMIT 0 , 7

das ist das ergebnis...

zak... und neu?? wappler 1103577806
zak... und neu?? tomstig 1101470491
jj tomstig 1101421349
jj tomstig 1101421332
jj tomstig 1101421317
jj tomstig 1101421302
jj tomstig 1101421287


sprich "zak... und neu" würde 2x angezeigt werden - genauso wie jj...


h4de5 schrieb am 20.12.2004 um 22:55

a group by t.topic_title gehört vors order by
und beim select max(p.post_time)

bei u.username und gehört noch a 2. aggregatfunktion. aba da fällt ma jez nix ein.

edit also so ähnlich:

Code: PHP
SELECT DISTINCT t.topic_title, u.username, max(p.post_time)
FROM `posts` p
LEFT JOIN topics t
USING ( topic_id )
LEFT JOIN users u ON u.user_id = p.poster_id
group by t.topic_title, u.username
ORDER BY p.post_time DESC
LIMIT 0 , 7 

aber das passt noch ned ganz. weil dann wahrscheinlich "zak... und neu??" wieder zweimal kommt (unterschiedlicher poster)

edit2: hiaz hammas :cool:
Code: PHP
SELECT DISTINCT t.topic_id, t.topic_title, max(p.post_id), u.username, max(p.post_time)
FROM `posts` p
INNER JOIN topics t ON t.topic_last_post_id = p.post_id
INNER JOIN users u ON u.user_id = p.poster_id
GROUP BY t.topic_id, t.topic_title, u.username
ORDER BY p.post_time DESC
LIMIT 0 , 7 

obwohl, wenn ich mir des recht überlege, wär a subselect noch immer gscheita. aba dafür bin i hiaz zmüde :(


watchout schrieb am 21.12.2004 um 00:08

bei oc funkt das aber anders - und zwar über den thread-table, alles andere tät zu viel peromance schlucken ;)




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2026