Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MYSQL/PHP] Nie wydajne zapytanie ?
b4x
post
Post #1





Grupa: Zarejestrowani
Postów: 658
Pomógł: 95
Dołączył: 20.12.2005
Skąd: N54,35° E18,63° (Gdańsk)

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


  1. <?php
  2. function check_uonline($id) {
  3.  
  4. $p = mysql_fetch_array(mysql_query('SELECT `online` FROM `users` WHERE `id` = "'.$id.'"'));
  5.  
  6. return $p['online'];
  7.  
  8. }
  9.  
  10. function friends_online($user) {
  11.  
  12. $u = mysql_query('SELECT `friend` FROM `friends` WHERE `user_id` = "'.$user.'" AND `status` = "1"');
  13.  
  14.  while($row = mysql_fetch_assoc($u)) {
  15.  
  16. if($this->check_uonline($row['friend']) >= 1) {
  17.  
  18. $i++;
  19.  
  20. }
  21.  
  22. }
  23.  
  24. return $i;
  25.  
  26. }
  27.  
  28. function count_stats_users($user) {
  29.  
  30. $online = mysql_num_rows(mysql_query('SELECT `id` FROM `users` WHERE `online` > "0"'));
  31. $total = mysql_num_rows(mysql_query('SELECT `id` FROM `users`'));
  32. $friends_to_accept = mysql_num_rows(mysql_query('SELECT * FROM `friends` WHERE `user_id` = "'.$user.'" AND `inviter` = "0" AND `status` = "0"'));
  33. $messages = mysql_num_rows(mysql_query('SELECT `id` FROM `messages` WHERE `to` = "'.$user.'"'));
  34. $new_messages = $this->msgs_count($user);
  35.  
  36.  
  37. $array = array('online' => $online, 'total' => $total, 'friends_accept' => $friends_to_accept, 'friends_online' => $this->friends_online($user), 'messages' => $messages, 'new_messages' => $new_messages);
  38.  
  39. return $array;
  40.  
  41. }
  42. ?>


Nie wiem, jak zrobić, by było to bardziej wydajniejsze.. Ktoś pomoże ?

Ten post edytował b4x 25.07.2008, 10:23:57
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 15.09.2025 - 08:47