Rateing systeem

Gestart doorOne2xs11 reacties34 weergaven

12 berichten · pagina 1 van 1

One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
ik heb een rating systeem
nu heb ik in de DB zo staan:
Door Voor Stem
Door = door wie er is gestemd
Voor = op wie er is gestemd
Stem = wat er is gestemd (0 T/M 5)
Nu wil ik het gemiddelde cijfer bepalen met PHP
Maar hier ben ik NIET goed in
Dus wie zou kunnen helpen?
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$rating[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"
SELECT
SUM(Stem) AS totaal,
COUNT(Stem) as aantal
FROM
TABEL
"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rating[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Gemiddeld: [/COLOR] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]totaal[/COLOR][COLOR= #007700]][/COLOR] / [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]]);[/COLOR]
?>
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Ik krijg dit:
niels heeft 3 stemmen
niels heeft een gemiddelde rating van 3.66666666667

[COLOR= #0000BB]<?php
            $counts[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT SUM(rate) AS totaal, COUNT(rate) AS aantal FROM rates WHERE voor = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
            [COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$counts[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] stemmen<br />[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft een gemiddelde rating van [/COLOR][COLOR= #007700]. ([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]totaal[/COLOR][COLOR= #007700]][/COLOR] / [COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]]);[/COLOR]
?>


Maar achter de . hoeft niet xd
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
            $counts[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT SUM(rate) AS totaal, COUNT(rate) AS aantal FROM rates WHERE voor = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
            [COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$counts[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] stemmen<br />[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft een gemiddelde rating van [/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/round"]round[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]totaal[/COLOR][COLOR= #007700]][/COLOR] / [COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR]
?>
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
TNX
en als iemand 0 stemmen heeft en een rating van 0 dus krijg ik dit:
Warning: Division by zero in /home/jeffie/domains/helpmijnsite.v3host.nl/public_html/profiel.php on line 274
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Moet het naar boven of naar onder?

*Tip* google
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Alemaalte schreef:
Moet het naar boven of naar onder?
*Tip* google

wil je een hoger post aantal?
dit slaat NERGENS op
0
Berichten
5.795
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$counts[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT SUM(rate) AS totaal, COUNT(rate) AS aantal FROM rates WHERE voor = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
            [COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$counts[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] stemmen<br />[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft een gemiddelde rating van [/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/round"]round[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]totaal[/COLOR][COLOR= #007700]][/COLOR] / [COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]totaal[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]0[/COLOR][COLOR= #007700]) {[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Deze gebruiker heeft nog geen stemmen of een 0 gemiddeld[/COLOR][COLOR= #007700];
}[/COLOR]
?>


dat mischien?
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
            $counts[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT SUM(rate) AS totaal, COUNT(rate) AS aantal FROM rates WHERE voor = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
            [COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$counts[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft [/COLOR] [COLOR= #007700]. ([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] >[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] :[/COLOR] [COLOR= #DD0000]geen[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] stemmen<br />[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] >[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000] heeft een gemiddelde rating van [/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/round"]round[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]totaal[/COLOR][COLOR= #007700]][/COLOR] / [COLOR= #0000BB]$count[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]);
            }[/COLOR]
?>


Alemaalte bedoeld naar boven of naar beneden afronden
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Nog steeds
EDIT:
van luuk werkt smile
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nielsie ik bedoelde inderdaad naar boven of nar beneden afronden.
En ik had niet gezien dat het tablad al bijna een half uur open stond hypocrite
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
xdmaakt niet uit
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren