Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php|mysql] pare razy COUNT w jednym zapytaniu
tommy4
post
Post #1





Grupa: Zarejestrowani
Postów: 288
Pomógł: 12
Dołączył: 2.12.2005

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


witam mam maly problem
chcialbym te zapytania:

  1. <?php
  2. $id = $userdata['id'];
  3. $sql = "SELECT COUNT(*) AS newscount FROM news WHERE author = $id";
  4. $sqlq = @mysql_query($sql);
  5. $sql = "SELECT COUNT(*) AS articlescount FROM articles WHERE author = $id";
  6. $sqlq2 = @mysql_query($sql);
  7. $sql = "SELECT COUNT(*) AS shotscount FROM shots WHERE user = $id";
  8. $sqlq3 = @mysql_query($sql);
  9. $sql = "SELECT COUNT(*) AS carscount FROM cars WHERE author = $id";
  10. $sqlq4 = @mysql_query($sql);
  11. $sql = "SELECT COUNT(*) AS shoutscount FROM shouts WHERE user = $id";
  12. //$sql = "SELECT COUNT(*) AS filmscount FROM films WHERE author = $id";
  13. $sql = "SELECT COUNT(*) AS commentscount FROM comments WHERE user = $id";
  14. $sqlq6 = @mysql_query($sql);
  15. ?>


chcialbym te wszystkie count w jednym zapytaniu mozna tak?

probowalem:

$sql = "SELECT COUNT(news.id) AS newscount, COUNT(articles.id) AS articlescount FROM news AS news, articles AS articles WHERE news.author = $id AND articles.author = $id"

ale wychodza jakies dziwne wyniki.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
AxZx
post
Post #2





Grupa: Zarejestrowani
Postów: 1 385
Pomógł: 55
Dołączył: 1.03.2005
Skąd: śląsk

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


polacz te zapytania UNION i bedzie jako jedno zapytanie


--------------------
aplikacje internetowe | Symfony
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 Aktualny czas: 21.08.2025 - 11:38