Author Topic: php question (user rating)  (Read 8656 times)

0 Members and 1 Guest are viewing this topic.

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
php question (user rating)
« on: July 11, 2005, 03:17:02 PM »
hi i'm trying to make a user rating so the user can vote others users like the  Karma system in this forum

i'm a newbie in php but i have almost finished

i have this code

Code: [Select]
$total = $vote_a+$vote_b+$vote_c+$vote_d+$vote_e;
$sum = round(((($vote_a*1)+($vote_b*2)+($vote_c*3)+($vote_d*4)+($vote_e*5))/$total)*2 , 2);

but when the $total is cero i get this error

Quote
Warning: Division by zero in /home/ascanio/domains/girlsandgirls.net/public_html//index.php on line 66

what can i do?

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: php question (user rating)
« Reply #1 on: July 11, 2005, 03:39:25 PM »
just thinking
$sum = round(((($vote_a*1)+($vote_b*2)+($vote_c*3)+($vote_d*4)+($vote_e*5))
$sum1 = if $sum =< 0 then 0    else sum/(sum*2 , 2);

not sure if it is possible  :wink:

just i mean add what you have to add than check if it is > 0 then calculate!

vincent  :oops:

Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: php question (user rating)
« Reply #2 on: July 11, 2005, 04:18:55 PM »
thank but i get this
Parse error: parse error, unexpected T_IF

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: php question (user rating)
« Reply #3 on: July 11, 2005, 04:24:31 PM »
 :roll:
i think so - it was only a path i showed - not a finished code!

i think the problem was 0 / x = error
so you add as much you like then check if > 0 then you calculate

sincerly
vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: php question (user rating)
« Reply #4 on: July 11, 2005, 04:36:50 PM »
sorry i don't know how to do it  :oops: :oops: :oops:

TheOracle

  • Guest
Re: php question (user rating)
« Reply #5 on: July 11, 2005, 11:13:08 PM »
How about posting the whole index.php file since it seems to involve bigger modifications to get this MOD to work ? ;)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: php question (user rating)
« Reply #6 on: July 12, 2005, 12:12:38 AM »
if ($total)
{
  $sum = round(((($vote_a*1)+($vote_b*2)+($vote_c*3)+($vote_d*4)+($vote_e*5))/$total)*2 , 2);
}
else
{
  $sum = 0;
}
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: php question (user rating)
« Reply #7 on: July 12, 2005, 04:29:38 PM »
thanks :)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: php question (user rating)
« Reply #8 on: July 13, 2005, 12:22:29 AM »
btw, basic algebra, red = not needed ;) :
Quote
((($vote_a*1)+($vote_b*2)+($vote_c*3)+($vote_d*4)+($vote_e*5))/$total)*2
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: php question (user rating)
« Reply #9 on: July 13, 2005, 01:06:20 AM »
ok thanks, i'm learning ..  i did that just to make sure :)

Offline cipriansamoila

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: php question (user rating)
« Reply #10 on: August 07, 2005, 04:06:20 AM »
How do you rate an image the following way:

Do you like this image? Yes or No?

A pro / contra system.

I tried changing the values to yes and no, and the database to accept varchar instead of integer, but there is still some code in counting the votes.

In the end, I want to count how many yes and how many no are for each image.

Thanks.
Cip