Guest User

Untitled

a guest
May 27th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. jQuery works only half the time
  2. <?php
  3. $data = mysql_query("SELECT * FROM Contests");
  4.  
  5. while($row = mysql_fetch_array( $data )){
  6. $query = mysql_query("SELECT * FROM userContests WHERE userID='$userID' AND contestID='$row[contestID]';") or die(mysql_error());
  7. $checked = mysql_fetch_assoc($query);
  8. ?>
  9.  
  10. <script type="text/javascript">
  11. $(document).ready(function() {
  12. var checked = <?php echo $checked['value']; ?>;
  13. var postID = <?php echo $row['postID']; ?>;
  14. var userID = <?php echo $current_user->ID; ?>;
  15.  
  16. if (checked == 1) {
  17. $('#post_<?php echo $row['postID']; ?>').addClass('like');
  18. } else if (checked == 0) {
  19. $('#post_<?php echo $row['postID']; ?>').addClass('dislike');
  20. }
  21.  
  22. $('#like_<?php echo $row['postID']; ?>').click(function(liked) {
  23.  
  24. $.ajax({
  25. url: 'check.php',
  26. type: 'POST',
  27. data: 'userID=' + userID + '&postID=' + postID + '&value=' + '1',
  28. success: function(result) {
  29. $('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
  30. }
  31. });
  32.  
  33. $('#post_<?php echo $row['postID']; ?>').removeClass('dislike').addClass('like');
  34. if (showLikes.attr('checked')) {
  35. $('#post_<?php echo $row['postID']; ?>').toggle();
  36. }
  37. });
  38.  
  39. $('#dislike_<?php echo $row['postID']; ?>').click(function(disliked) {
  40.  
  41. $.ajax({
  42. url: 'check.php',
  43. type: 'POST',
  44. data: 'userID=' + userID + '&postID=' + postID + '&value=' + '0',
  45. success: function(result) {
  46. $('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
  47. }
  48.  
  49. $('#post_<?php echo $row['postID']; ?>').removeClass('like').addClass('dislike');
  50. if (showDislikes.attr('checked')) {
  51. $('#post_<?php echo $row['postID']; ?>').toggle();
  52. }
  53. });
  54.  
  55. <div id="post_<?php echo $row['postID']; ?>" class="post">
  56. <div id="post_<?php echo $row['postID']; ?>_inside">
  57. <div>
  58. <a id="like_<?php echo $row['postID']; ?>" class="like" href="#"><span></span></a>
  59. </div>
  60. <div>
  61. <a id="dislike_<?php echo $row['postID']; ?>" class="dislike" href="#"><span></span></a>
  62. </div>
  63. <b><?php echo $row['Title']; ?></b><br>
  64. Expires: <?php echo $row['Exp']; ?><br>
  65. <ul id="listM"></ul>
  66. </div>
  67. </div>
  68. <div id="Message_<?php echo $row['postID']; ?>" class="reminder"></div>
  69.  
  70. <?php
  71. }
  72. ?>
  73.  
  74. a.like {
  75. float: right;
  76. background: url(images/entered.png) no-repeat top center;
  77. height: 30px;
  78. width: 28px;
  79. }
  80.  
  81. a.like:active {
  82. float: right;
  83. background: url(images/entered.png) no-repeat bottom center;
  84. height: 30px;
  85. width: 28px;
  86. }
  87.  
  88. a.dislike {
  89. float: right;
  90. background: url(images/not-interested.png) no-repeat top center;
  91. height: 30px;
  92. width: 28px;
  93. }
  94.  
  95. a.dislike:active {
  96. float: right;
  97. background: url(images/not-interested.png) no-repeat bottom center;
  98. height: 30px;
  99. width: 28px;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment