show the votes on my website?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
masomehs
Forum Newbie
Posts: 1
Joined: Mon Oct 25, 2004 1:53 am

show the votes on my website?

Post by masomehs »

Hi!

i just created a poll(voting script).
and i want the script to show how many that have voted:
example:

Votes
Nice page: 20 votes
Ugly page: 15 votes

The poll is connected to the database and work perfectly , when you vote it saves in the database. but i dont know how to do so it shows in the website how many votes there is. and i want them to only vote once! not many times. i guess i must use Cookies for that. i could need some help with that to.

Well, here is the code:

Code: Select all

<?  
if(isset($_POST&#1111;'vote'])) &#123;  
echo "Du röstade på alternativ nummer ".$_POST&#1111;'vote'];  
&#125;  
$sql = "UPDATE vote SET roster=roster+1 WHERE alternativ=$_POST&#1111;vote]";  
include_once 'connect.php';  
mysql_query($sql);  
?>
If you need the html code to, just tell me =).

Thanks, Masomehs
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

select sum(roster) from vote
allowing people to vote only once could be done with cookies (although they might delete the cookie and vote again.) you could also require them to login and then store if they already voted.
Post Reply