Jump to content

[QUESTION] Would this be possible?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
michaelholt

michaelholt

    Newbie

  • Members
  • Pip
  • 2 posts
Right, so I have seen these and have an idea on something i want to build.

I'm not going to go into specifics, but it would look like this.

Category A - Category B
VOTE VOTE

And after the user has voted, the vote buttons would be grayed out (or removed) and replaced by percentages on the vote.

i.e.

Category A - Category B
47% 53%

-----

Would be very grateful if someone could help. Who knows, you may even get credited in the completed project :)

-
Michael

(I believe this would be PHP, if not, can someone guide me the way? I'm new to programming, but can design/develop sites)

#2
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
Well, there are many details that should be taken into consideration, but at first sight there are two possibilities:

  • When a button is pressed, reload the full page and replace the buttons with the percentages

    This is very simple and all the work is done in the server side (with PHP). When the user presses a button, a request is sent to the server, which processes the vote and renders the new HTML page, writing the actual percentages instead of the buttons.


  • When a button is pressed, send an AJAX request to update the percentages, receive them and update the page dynamically with javascript

    It's a little more complex, but it's faster and offers a greater experience to the user. You send an AJAX request to the server indicating which one of the buttons the user pressed. In the server side, a PHP script must handle this data and return the actual percentages to the client. Using javascript, the client removes the buttons and writes the percentages so that the user can see them.
In both cases you must track which users have voted in some way to avoid duplicate votes or other problems.

#3
michaelholt

michaelholt

    Newbie

  • Members
  • Pip
  • 2 posts
I think I'll go for #1 then, as it is obviously easier.

As with the anti-duplicates, I'm sure something which would log which IP's have voted is available.

Do you know of any tuts which could get me going with this?

#4
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
Well, using the IP may be problematic with people reaching you through a proxy server. Another option is using cookies, but then you don't have the absolute control because the user could delete the cookie and vote again. If the users are identified in some way, it's easier, if not, it could be very hard to do a reliable voting method.

Sorry, I haven't read any tutorial about this (never needed to). I don't know a good one.

#5
TeenChristian

TeenChristian

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 639 posts

Quote

Category A - Category B
VOTE VOTE

And after the user has voted, the vote buttons would be grayed out (or removed) and replaced by percentages on the vote.

i.e.

Category A - Category B
47% 53%

Thats actually a good idea, I might use it :D (except with C++)
My Personal Blog l Learning C++ l I'll be famous soon enough.

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
You could always start a session (assuming you know how) (relies on PHPSESSION cookie, so may be obscure to the user)
session_start();
Then push the poll ID into a session variable, to more or less avoid extra cookies per poll once voted:
$pollid = $_GET['pollid']; //23145
if(is_numeric($pollid)) {
    $_SESSION['voted'][] = $pollid;
}
Then check it on each poll:
if(in_array($_GET['pollid'], $_SESSION['voted'])) {
    print "Already voted.";
}

dbug is right though, an IP being stored is harder and may be bypassed anyway, it's up to you what you want to choose though.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.