Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Single user allowed to rate multiple times?  (Read 6928 times)

0 Members and 1 Guest are viewing this topic.

bhenkel

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Single user allowed to rate multiple times?
« on: April 15, 2006, 07:57:07 pm »

Hello,

Is there a way to allow a single user to make multiple rating on single photo, and avoid the "You have already rated this photo" message?  Thanks in advance for your help.

« Last Edit: March 13, 2007, 11:21:30 pm by Nibbler »
Logged

Nibbler

  • Guest
Re: Single user allowed to rate multiple times?
« Reply #1 on: April 15, 2006, 09:08:07 pm »

Remove the check from ratepic.php

Code: [Select]
// Check if user already rated this picture
$user_md5_id = USER_ID ? md5(USER_ID) : $USER['ID'];
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_VOTES']} " . "WHERE pic_id = '$pic' AND user_md5_id = '$user_md5_id'";
$result = cpg_db_query($sql);
if (mysql_num_rows($result)) cpg_die(ERROR, $lang_rate_pic_php['already_rated'], __FILE__, __LINE__);
Logged

bhenkel

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Single user allowed to rate multiple times?
« Reply #2 on: April 16, 2006, 12:02:34 am »

Thanks for your reply, Nibbler.  I tried removing that code and received a "There was an error processing a database query" after trying to rate pic a second time.  Do you know anything about this?  Thanks for your help.
Logged

Nibbler

  • Guest
Re: Single user allowed to rate multiple times?
« Reply #3 on: April 16, 2006, 12:23:12 am »

Sorry, put this line back in

Code: [Select]
$user_md5_id = USER_ID ? md5(USER_ID) : $USER['ID'];
Logged

bhenkel

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Single user allowed to rate multiple times?
« Reply #4 on: April 16, 2006, 02:29:29 am »

Hmmm, still did it.  Maybe something with my database.  Thanks Nibbler!
Logged

Spot_69

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Single user allowed to rate multiple times?
« Reply #5 on: February 01, 2007, 09:10:29 pm »

Hi there,

   I would like to make a change similar to this, and am having a similar problem.

   Goal: allow users to re-rate pictures at their whim, without incrementing the rating counter, just changing the rating stored in the database for that user

   Questions:
       - how do I take out the check for whether or not the user has already rated, without causing a database access error?
       - how do I make it so that subsequent ratings do not increment the ratings counter, and/or do not get stored as additional ratings?

   I'll try and dig into this further myself, but my SQL skills are very limited, my initial attempts at messing about with ratepic.php were not all that successful, and any help would be greatly appreciated.

   Thanks in advance!


Logged

zac

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 153
Re: Single user allowed to rate multiple times?
« Reply #6 on: March 12, 2007, 11:30:28 am »

Another vote for this.. I tried that too Nibbler.. same problem.
Logged

Spot_69

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Single user allowed to rate multiple times?
« Reply #7 on: March 12, 2007, 06:15:54 pm »

For what it's worth - I tried to dig into this further as promised, and failed miserably.

Any further help would be greatly appreciated!
Logged

Nibbler

  • Guest
Re: Single user allowed to rate multiple times?
« Reply #8 on: March 12, 2007, 10:40:41 pm »

Code: [Select]
$sql = "INSERT INTO {$CONFIG['TABLE_VOTES']} " . "VALUES ('$pic', '$user_md5_id', '$curr_time')";
Try making that a REPLACE instead.
Logged

zac

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 153
Re: Single user allowed to rate multiple times?
« Reply #9 on: March 13, 2007, 12:48:10 am »

closer.. now it counts and calculates the votes... however it still sends me to the critical error page [error while processing database query] each time I click on the voting after the first vote.
Logged

zac

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 153
Re: Single user allowed to rate multiple times?
« Reply #10 on: March 13, 2007, 12:52:21 am »

Thought I should add that I am trying this in conjunction with SaWey's Nicer voting mod:

http://forum.coppermine-gallery.net/index.php?topic=40762.0

Logged

zac

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 153
Re: Single user allowed to rate multiple times?
« Reply #11 on: March 13, 2007, 09:45:15 pm »

Here is the debug error message in case anyone has a clue how to fix this.. guess I need to hack the SQL ?

Quote
While executing query "INSERT INTO cpg149_votes VALUES ('1810', '', '1173818542')" on 0

mySQL error: Duplicate entry '1810-' for key 1
Logged

Nibbler

  • Guest
Re: Single user allowed to rate multiple times?
« Reply #12 on: March 13, 2007, 10:04:12 pm »

this and this should solve that.
Logged

zac

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 153
Re: Single user allowed to rate multiple times?
« Reply #13 on: March 13, 2007, 10:17:01 pm »

Hmmmm.. guess it is right in front of me.. I feel like I have tried every combo I could from your instructions  ???

I replaced this block :
Code: [Select]
// Check if user already rated this picture
$user_md5_id = USER_ID ? md5(USER_ID) : $USER['ID'];
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_VOTES']} " . "WHERE pic_id = '$pic' AND user_md5_id = '$user_md5_id'";
$result = cpg_db_query($sql);
if (mysql_num_rows($result)) cpg_die(ERROR, $lang_rate_pic_php['already_rated'], __FILE__, __LINE__);

with this:
Code: [Select]

$sql = "INSERT INTO {$CONFIG['TABLE_VOTES']} " . "VALUES ('$pic', '$user_md5_id', '$curr_time')";

and this:

Code: [Select]
$sql = "INSERT INTO {$CONFIG['TABLE_VOTES']} " . "VALUES ('$pic', '$user_md5_id', '$curr_time')";
$user_md5_id = USER_ID ? md5(USER_ID) : $USER['ID'];

Thanks for your help.  I dont even know what I am looking at.



Logged

Nibbler

  • Guest
Re: Single user allowed to rate multiple times?
« Reply #14 on: March 13, 2007, 10:20:32 pm »

You remove this code

Code: [Select]
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_VOTES']} " . "WHERE pic_id = '$pic' AND user_md5_id = '$user_md5_id'";
$result = cpg_db_query($sql);
if (mysql_num_rows($result)) cpg_die(ERROR, $lang_rate_pic_php['already_rated'], __FILE__, __LINE__);

and change the query here

Code: [Select]
$sql = "INSERT INTO {$CONFIG['TABLE_VOTES']} " . "VALUES ('$pic', '$user_md5_id', '$curr_time')";

to a REPLACE

Code: [Select]
$sql = "REPLACE INTO {$CONFIG['TABLE_VOTES']} " . "VALUES ('$pic', '$user_md5_id', '$curr_time')";
Logged

zac

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 153
Re: Single user allowed to rate multiple times?
« Reply #15 on: March 13, 2007, 11:06:44 pm »

Ahhhhh yes !  Sorry for being dense Nibbler.  Thanks for spelling it out for me !  ;D
Logged

dan52

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Single user allowed to rate multiple times?
« Reply #16 on: September 18, 2007, 03:27:34 pm »

Hi

There are some problems with the solution you're offering here.
If you make those changes - the table data will be updated, and re-votes WILL be allowed.... BUT

1. for the picture, number of votes will continue to increase - even if re-votes are done.
This is wrong, especially since the rating is calculated as division by num_votes + 1 every time.

2. Also, a summary of ratings is kept, and each re-vote is added to that sum.
So in real, the REPLACE you're doing there is not effective: because the rating keeps growing and growing.
(even through the votes table contains the correct number of votes...)

So what you will see is two things:
a. your number of votes per pic will keep growing with each re-vote
b. Your vote average will go 'crazy' with some wierd number which is not an average of nothing really...

To make this problem more 'spicy', you cannot mod the vote summary, because you'd need to first substract the prev vote, and then add the new re-vote and then redo the avg. but you cannot - since you don't know the old vote value (!)

If you'd like to implement this correctly, I can suggest this:

1. Change the votes table to have another column - which is the vote value for each vote.
2. remove the columns for 'number of votes', and 'pic rating' from the pics table!. You don't need those!
3. use SQL commands COUNT() and AVG() functions to get data about pic rating!
-> have SQL do all the 'dirty' work for you for calculations. All the wierd calcs you're doing in ratepic.php are not needed.
Just store the data in SQL, and when you SELECT it back do a nested SELECT to get the AVG and COUNT per picture.

I hope this is helpful,
Dan

PS - I'm working with code in CGP 1.4.13
Logged
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 21 queries.