Advertisement
Guest User

Untitled

a guest
Dec 29th, 2010
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.82 KB | None | 0 0
  1. <?php
  2. include("config.php");
  3. ?>
  4.  
  5. <html>
  6. <head>
  7.     <title>Votes</title>
  8.    
  9. <style type='text/css'>
  10. body {
  11.     background: #e8e6de;
  12. }
  13.  
  14. a {
  15. outline:none;
  16. }
  17.  
  18. .entry {
  19.     width: 710px;
  20.     background: #ffffff;
  21.     padding:8px;
  22.     border:1px solid #bbbbbb;
  23.     margin:5px auto;
  24.     -moz-border-radius:8px;
  25. }
  26.  
  27. span.link a {
  28.     font-size:150%;
  29.     color: #000000;
  30.     text-decoration:none;
  31. }
  32.  
  33. a.vote_up, a.vote_down {
  34.     display:inline-block;
  35.     background-repeat:none;
  36.     background-position:center;
  37.     height:16px;
  38.     width:16px;
  39.     margin-left:4px;
  40.     text-indent:-900%;
  41. }
  42.  
  43. a.vote_up {
  44.     background:url("images/thumb_up.png");
  45. }
  46.  
  47. a.vote_down {
  48.     background:url("images/thumb_down.png");
  49. }
  50. </style>
  51.  
  52. <script type='text/javascript' src='jquery.pack.js'></script>
  53. <script type='text/javascript'>
  54. $(function(){
  55.     $("a.vote_up").click(function(){
  56.     //get the id
  57.     the_id = $(this).attr('id');
  58.    
  59.     // show the spinner
  60.     $(this).parent().html("<img src='images/spinner.gif'/>");
  61.    
  62.     //fadeout the vote-count
  63.     $("span#votes_count"+the_id).fadeOut("fast");
  64.    
  65.     //the main ajax request
  66.         $.ajax({
  67.             type: "POST",
  68.             data: "action=vote_up&id="+$(this).attr("id"),
  69.             url: "votes.php",
  70.             success: function(msg)
  71.             {
  72.                 $("span#votes_count"+the_id).html(msg);
  73.                 //fadein the vote count
  74.                 $("span#votes_count"+the_id).fadeIn();
  75.                 //remove the spinner
  76.                 $("span#vote_buttons"+the_id).remove();
  77.             }
  78.         });
  79.     });
  80.    
  81.     $("a.vote_down").click(function(){
  82.     //get the id
  83.     the_id = $(this).attr('id');
  84.    
  85.     // show the spinner
  86.     $(this).parent().html("<img src='images/spinner.gif'/>");
  87.    
  88.     //the main ajax request
  89.         $.ajax({
  90.             type: "POST",
  91.             data: "action=vote_down&id="+$(this).attr("id"),
  92.             url: "votes.php",
  93.             success: function(msg)
  94.             {
  95.                 $("span#votes_count"+the_id).fadeOut();
  96.                 $("span#votes_count"+the_id).html(msg);
  97.                 $("span#votes_count"+the_id).fadeIn();
  98.                 $("span#vote_buttons"+the_id).remove();
  99.             }
  100.         });
  101.     });
  102. });
  103. </script>
  104.  
  105. </head>
  106. <body>
  107.  
  108. <?php
  109. /**
  110. Display the results from the database
  111. **/
  112. $q = "SELECT * FROM entries";
  113. $r = mysql_query($q);
  114.  
  115. if(mysql_num_rows($r)>0): //table is non-empty
  116.     while($row = mysql_fetch_assoc($r)):
  117.         $up = $row['votes_up'] ;
  118.         $down = $row['votes_down']; //this is the net result of voting up and voting down
  119. ?>
  120. <div class='entry'>
  121.  
  122.     <span class='link'>
  123.         <a href='<?php echo $row['link']; ?>'> <?php echo $row['title']; ?> </a>
  124.     </span>
  125.    
  126.     <span class='votes_count' id='votes_count<?php echo $row['id']; ?>'><?php echo $up." up votes"; ?></span>
  127.    
  128.     <span class='vote_buttons' id='vote_buttons<?php echo $row['id']; ?>'>
  129.         <a href='javascript:;' class='vote_up' id='<?php echo $row['id']; ?>'>Vote Up!</a>
  130.         <a href='javascript:;' class='vote_down' id='<?php echo $row['id']; ?>'>Vote Down!</a>
  131.     </span>
  132.    
  133. </div>
  134. <?php
  135.     endwhile;
  136. endif;
  137. ?>
  138.  
  139.  
  140. </body>
  141. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement