Jump to content

I can't figure out for the life of me what's wrong with this insert snippet...


Padgoi

Recommended Posts

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.

Link to comment
Share on other sites

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!";
       }

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.