![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 8 Pomógł: 0 Dołączył: 2.01.2008 Ostrzeżenie: (0%) ![]() ![]() |
Witam mam 3 tablele o zawartości:
CODE -- -- Struktura tabeli dla `db_dane` -- CREATE TABLE `db_dane` ( `id` smallint(6) NOT NULL auto_increment, `user_id` smallint(6) NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM ; -- -------------------------------------------------------- -- -- Struktura tabeli dla `db_ratings` -- CREATE TABLE `db_ratings` ( `rating_id` smallint(5) unsigned NOT NULL auto_increment, `rating_item_id` smallint(5) unsigned NOT NULL default '0', `rating_type` char(1) NOT NULL default '', `rating_user` smallint(5) unsigned NOT NULL default '0', `rating_vote` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`rating_id`) ) TYPE=MyISAM ; -- -------------------------------------------------------- -- -- Struktura tabeli dla `db_users` -- CREATE TABLE `db_users` ( `user_id` smallint(5) unsigned NOT NULL auto_increment, PRIMARY KEY (`user_id`) ) TYPE=MyISAM ; Prosiłbym bardzo aby mi ktoś stworzył funkcję wyświetlającą średnią ocenę na podstawie zmiennej $user_id wziętej z user_id w db_users. Średnia wziętą ze wszystkich pól rating_vote (tzn. SELECT SUM(rating_vote) / COUNT(rating_item_id) ) gdzie rating_item_id zawiera id z db_dane w którym user_id to ta nasza zmienna podawana przy funkcji. Od kilku godzin już się nad tym głowię i niestety brak postępów. Dopiero raczkuję w temacie mysql więc będę za wszelką pomoć wdzięczny |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 508 Pomógł: 75 Dołączył: 2.11.2005 Skąd: Bydgoszcz Ostrzeżenie: (0%) ![]() ![]() |
Jaki ja jestem nieuwazny... Brak slow i wstyd (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Klauzula WHERE musi byc zawsze przed GROUP BY... Kod SELECT AVG( rat.rating_vote ) FROM ep_ratings rat, ep_poezja poezja WHERE poezja.user_id = '$user_id' GROUP BY poezja.user_id AND poezja.user_id = rat.rating_item_id Wielkie sory za problemy, ale czasami sa takie dni (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) |
|
|
![]() ![]() |
![]() |
Aktualny czas: 8.10.2025 - 03:20 |