Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MYSQL]Jak pominąć ten błąd?
smietek
post 22.08.2009, 10:38:53
Post #1





Grupa: Zarejestrowani
Postów: 306
Pomógł: 32
Dołączył: 20.01.2008

Ostrzeżenie: (20%)
X----


Mam problem z takim zapytaniem:
  1. SELECT
  2. count(`articles_comments`.`id`) AS `art_comms`,
  3. count(`comment_news`.`id`) AS `news_comms`,
  4. count(`articles_votes`.`id`) AS `art_votes`,
  5. count(`survey_votes`.`id`) AS `surv_votes`,
  6. count(`shoutbox`.`id`) AS `shout`
  7. FROM `users`
  8. LEFT JOIN `shoutbox` ON `shoutbox`.`user_id` = `users`.`id`
  9. LEFT JOIN `survey_votes` ON `survey_votes`.`user_id` = `users`.`id`
  10. LEFT JOIN `articles_votes` ON `articles_votes`.`user_id` = `users`.`id`
  11. LEFT JOIN `comment_news` ON `comment_news`.`author_id` = `users`.`id`
  12. LEFT JOIN `articles_comments` ON `articles_comments`.`user_id` = `users`.`id`
  13. WHERE `users`.`id` = $_SESSION[id]
  14. GROUP BY `users`.`id`

Wszystko jest dobrze, dopóki nie wyświetlę wyniku.
Na localhoście (mam XAMPPa) wszystko jest dobrze wyświetlane, a na wykupionym hostingu wszystko mi się zlewa, tzn. gdy dodam jakiś wpis do shoutboxa, to wszędzie tam, gdzie wartość nie jest zerowa to zlicza mi WSZYSTKO, czyli nie tylko Shoutboxa, ale i komentarze itd...
Czy to błąd MySQL?
Na XAMMPie mam: Wersja serwera: 5.0.51b-community, Wersja klienta MySQL: 5.0.51b
Na wirtualnym: Wersja serwera: 5.0.67-percona-b6-log, Wersja klienta MySQL: 4.1.22


--------------------
Go to the top of the page
+Quote Post
emp
post 22.08.2009, 11:07:07
Post #2





Grupa: Zarejestrowani
Postów: 195
Pomógł: 14
Dołączył: 12.01.2006
Skąd: Gotham City

Ostrzeżenie: (0%)
-----


Zapytanie jest źle skonstruowane. Poniżej moja propozycja bez grup by z użyciem podzapytań.

  1. SELECT
  2. ( SELECT count( id ) FROM articles_comments WHERE id_user = u.id) AS art_comms,
  3. ( SELECT count( id ) FROM comment_news WHERE author_id = u.id) AS news_comms,
  4. ( SELECT count( id ) FROM articles_votes WHERE id_user = u.id) AS art_votes,
  5. ( SELECT count( id ) FROM survey_votes WHERE id_user = u.id) AS surv_votes,
  6. ( SELECT count( id ) FROM shoutbox WHERE id_user = u.id) AS shout
  7. FROM USERS AS u WHERE u.id=$_SESSION[id]


Ten post edytował emp 22.08.2009, 11:11:40


--------------------
Temat zamykam i przenoszę do Bangladeszu.
To jest wiadomość śmierci jeśli ją czytasz to znaczy że pozostało ci 30 sekund życia, więc lepiej zacznij się modlić.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 21:59