Jump to content

Recommended Posts

I am trying to find some example code where the user could click a button to approve or disapprove a certain topic.  Or even like a voting type of code where they vote yes or no.

 

The database would just update a running count each time the user clicked on the approve or disapprove buttons. 

 

I'll also need each user to only be allowed to vote once on a particular topic.

 

Any ideas for some examples somewhere?

 

Seems like I could write something like

<?php

//topic variable passed through a link I assume
$topic = 2343;

//user clicks on approve
$approve = "UPDATE topic SET a_count = a_count + 1 WHERE topic_id = $topic";

//user clicks on disapprove
$disapprove = "UPDATE topic SET d_count = d_count + 1 WHERE topic_id = $topic";

//The rest I am unsure of how to control the user from clicking approve 500 times.  Maybe in a $_SESSION?

?>

Link to comment
https://forums.phpfreaks.com/topic/229417-approve-disapprove-code/
Share on other sites

<form>
<input type='submit' name='approve' />
</form>


<form>
<input type='submit' name='disapprove' />
</form>

if(isset($_POST['approve'])) {
"UPDATE topic SET a_count = a_count + 1 WHERE topic_id = $topic";
}
if(isset($_POST['disapprove'])) {
$disapprove = "UPDATE topic SET d_count = d_count + 1 WHERE topic_id = $topic";;
}

 

also just get their IP and store it so they can only vote once

also just get their IP and store it so they can only vote once

 

Thank you....That's defnitely an easy fix you've got there.

 

However, Wouldn't storing the IP fill up my database with a ton of information?  Is there a better way to handle that?

IP's can be spoofed. IP's change.  Lots of reasons why IP isn't a good idea.

 

 

If it were me, I would track it by a user ID, allowing only users to like or dislike.  Yes, for each item a user likes, it would add a row to the database.  You would need to think carefully about your indexes on this table, so that as it grew, you wouldn't have a serious bottleneck.  I also think you could safely delete rows that are older than 6 months.  Most topics don't stick around that long.  Or, clean them when you archive the topic.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.