Skipjackrick Posted March 2, 2011 Share Posted March 2, 2011 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? ?> Quote Link to comment Share on other sites More sharing options...
Rifts Posted March 2, 2011 Share Posted March 2, 2011 <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 Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted March 2, 2011 Author Share Posted March 2, 2011 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? Quote Link to comment Share on other sites More sharing options...
jcbones Posted March 3, 2011 Share Posted March 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.