Padgoi Posted March 29, 2009 Share Posted March 29, 2009 I have a ratings modification that allows users to rate posts on my forums. I'm trying to make it so that when a user rates a post, it will update 2 fields, the first one will add the rating to a field, the other will simply add +1 to the count of a custom field. The first part of it to update the ratings field works fine. But the second insert to update the count of the custom field isn't working at all, it's not adding the +1 to the count. Here's the snippet: } $MySQL = new MySQL( ); $postid = $_GET['p']; $userid = $_GET['u']; $rateid = $_GET['r']; $fields = array( '1' => '14', '2' => '19', '3' => '15', '4' => '23', '5' => '24', '6' => '22', '7' => '17', '8' => '13', '9' => '16', '10' => '28', '11' => '25', '12' => '29', '13' => '18', '14' => '31', '15' => '26', '16' => '30', '17' => '27', '18' => '32', ); $ratingCheck = $MySQL->customQuery( "SELECT r.rating,r.uid,p.* FROM ibf_ratings r LEFT JOIN ibf_posts p ON(r.pid=p.pid) WHERE r.pid = '{$postid}' AND r.uid = '{$userid}'"); // Yup, we've already rated this post so UPDATE the rating IF the rating is differant from the current one. if( $MySQL->rowsReturned( $ratingCheck ) ) { $row = $MySQL->fetchResults( $ratingCheck ); // If the current rating is equal to new rating, don't do anyhing... if( $_GET['r'] == $row['rating'] ) { echo "Rated!"; } else { [b]$MySQL->customQuery( "UPDATE `ibf_ratings` SET `rating` = '{$rateid}' WHERE `pid` = '{$postid}' AND `uid` = '{$userid}'"); $MySQL->customQuery( "UPDATE `ibf_pfields_content` SET ".$fields[$row['rating']]."=".$fields[$row['rating']]."-1,".$fields[$rateid]."=".$fields[$rateid]."+1 WHERE member_id='".$row['author_id']."'" );[/b] if( $MySQL->affectedRows( ) ) { echo "Rating changed!"; } } } else { $MySQL->insertQuery ( "ibf_ratings" , Array( 'pid' => $postid , 'uid' => $userid , 'rating' => $rateid ) ); [b]$MySQL->customQuery( "UPDATE `ibf_pfields_content` SET ".$fields[$rateid]."=".$fields[$rateid]."+1 WHERE member_id='".$row['author_id']."'" );[/b] echo "Rated!"; } } The part that I bolded is the part that is supposed to add the +1 to the custom field, but it's not adding. The top part with the fields array is simply associating each rating with a field, so rating 1 = field_14 and so on. The fields that are NOT updating are called field_14, field_15 and so on. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 you sue this is correct.. $MySQL->insertQuery ( "ibf_ratings" , Array( 'pid' => $postid , 'uid' => $userid , 'rating' => $rateid ) ); [b]$MySQL->customQuery( "UPDATE `ibf_pfields_content` SET ".$fields[$rateid]."=".$fields[$rateid]."+1 WHERE member_id='".$row['author_id']."'" );[/b] echo "Rated!"; } Quote Link to comment Share on other sites More sharing options...
Padgoi Posted March 29, 2009 Author Share Posted March 29, 2009 arrow, you're right, I got the top part working now where it changed the rating. But the bottom part, the part you pointed out, is not adding the rating to the custom field, it's not adding the +1. Do you know what's wrong with it? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 this condition $fields[$rateid] not matching the database dont no why. echo out the update pal. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted March 29, 2009 Author Share Posted March 29, 2009 What do you mean echo out the update? All I did to get the top part working was change the VERY TOP of the snipped to this: $fields = array( '1' => 'field_14', '2' => 'field_19', '3' => 'field_15', '4' => 'field_23', '5' => 'field_24', '6' => 'field_22', '7' => 'field_17', '8' => 'field_13', '9' => 'field_16', '10' => 'field_28', '11' => 'field_25', '12' => 'field_29', '13' => 'field_18', '14' => 'field_31', '15' => 'field_26', '16' => 'field_30', '17' => 'field_27', '18' => 'field_32', ); So now the top part that changes ratings works but the adding the +1 on a new rating still doesn't work. Any ideas? And if that condition isn't matching the database, then why does the top part that changes the rating now work? Wouldn't that not work as well? Only the add part doesn't work now. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 is int rateid under rating from the above array. 'rating' => $rateid big guess $fields[$ibf_ratings['ratings']] Quote Link to comment Share on other sites More sharing options...
Padgoi Posted March 29, 2009 Author Share Posted March 29, 2009 I'm sorry, my php isn't great, what do you mean is int rateid under rating from above array? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 $MySQL->insertQuery ( "ibf_ratings" , Array( 'pid' => $postid , 'uid' => $userid , 'rating' => $rateid ) ); above array is ibf_ratings['rating'] <<<< = ratedid i think does this make any difference dont no. <?php $MySQL->customQuery( "UPDATE `ibf_pfields_content` SET ".$fields[$ibf_ratings['rating']]."=".$fields[$ibf_ratings['rating']]."+1 WHERE member_id='".$row['author_id']."'" ); echo "Rated!"; ?> if it dosent work very sorry always learning arrays and mysql/php Quote Link to comment Share on other sites More sharing options...
Padgoi Posted March 29, 2009 Author Share Posted March 29, 2009 No sir, that did not work, still did not get added to the field. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 what about this last go sorry. <?php $MySQL->customQuery( "UPDATE `ibf_pfields_content` SET ".$fields[$mysql['rating']]."=".$fields[$mysql['rating']]."+1 WHERE member_id='".$row['author_id']."'" ); echo "Rated!"; ?> Quote Link to comment Share on other sites More sharing options...
Padgoi Posted March 29, 2009 Author Share Posted March 29, 2009 No sir, that did not work either. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 Post you database structure of ibf_pfields_content please. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.