- jQuery works only half the time
- <?php
- $data = mysql_query("SELECT * FROM Contests");
- while($row = mysql_fetch_array( $data )){
- $query = mysql_query("SELECT * FROM userContests WHERE userID='$userID' AND contestID='$row[contestID]';") or die(mysql_error());
- $checked = mysql_fetch_assoc($query);
- ?>
- <script type="text/javascript">
- $(document).ready(function() {
- var checked = <?php echo $checked['value']; ?>;
- var postID = <?php echo $row['postID']; ?>;
- var userID = <?php echo $current_user->ID; ?>;
- if (checked == 1) {
- $('#post_<?php echo $row['postID']; ?>').addClass('like');
- } else if (checked == 0) {
- $('#post_<?php echo $row['postID']; ?>').addClass('dislike');
- }
- $('#like_<?php echo $row['postID']; ?>').click(function(liked) {
- $.ajax({
- url: 'check.php',
- type: 'POST',
- data: 'userID=' + userID + '&postID=' + postID + '&value=' + '1',
- success: function(result) {
- $('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
- }
- });
- $('#post_<?php echo $row['postID']; ?>').removeClass('dislike').addClass('like');
- if (showLikes.attr('checked')) {
- $('#post_<?php echo $row['postID']; ?>').toggle();
- }
- });
- $('#dislike_<?php echo $row['postID']; ?>').click(function(disliked) {
- $.ajax({
- url: 'check.php',
- type: 'POST',
- data: 'userID=' + userID + '&postID=' + postID + '&value=' + '0',
- success: function(result) {
- $('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
- }
- $('#post_<?php echo $row['postID']; ?>').removeClass('like').addClass('dislike');
- if (showDislikes.attr('checked')) {
- $('#post_<?php echo $row['postID']; ?>').toggle();
- }
- });
- <div id="post_<?php echo $row['postID']; ?>" class="post">
- <div id="post_<?php echo $row['postID']; ?>_inside">
- <div>
- <a id="like_<?php echo $row['postID']; ?>" class="like" href="#"><span></span></a>
- </div>
- <div>
- <a id="dislike_<?php echo $row['postID']; ?>" class="dislike" href="#"><span></span></a>
- </div>
- <b><?php echo $row['Title']; ?></b><br>
- Expires: <?php echo $row['Exp']; ?><br>
- <ul id="listM"></ul>
- </div>
- </div>
- <div id="Message_<?php echo $row['postID']; ?>" class="reminder"></div>
- <?php
- }
- ?>
- a.like {
- float: right;
- background: url(images/entered.png) no-repeat top center;
- height: 30px;
- width: 28px;
- }
- a.like:active {
- float: right;
- background: url(images/entered.png) no-repeat bottom center;
- height: 30px;
- width: 28px;
- }
- a.dislike {
- float: right;
- background: url(images/not-interested.png) no-repeat top center;
- height: 30px;
- width: 28px;
- }
- a.dislike:active {
- float: right;
- background: url(images/not-interested.png) no-repeat bottom center;
- height: 30px;
- width: 28px;
- }