Page 1 of 1

Not updating records correctly & resseting counter to 0

Posted: Thu Jul 20, 2006 6:34 pm
by matt1019
Someone! Anyone! Please help me solve my misery!!!

I cannot get this thing to work and about to drive myself into insanity!

A simple task.... did i make it complex? not functioning as intended!

Heres what my goal was:
To create a simple Kiss Function.

User A kisses User B

User B gets a notification when he/she logs-in
---> Has two options:
1. Kiss Back
2. Ignore

This part works like a charm.

Here's the bug:

User A Kisses User B
User C Kisses User B

User B gets a notification when he/she logs-in
---> Has four options:
1. Kiss Back (person who kissed)
2. Ignore (person who kissed)
3. Kiss back all (kiss everyone who kissed him/her - in this case USER A and USER C)
4. Ignore All (ignore everyone who kissed him/her - in this case USER A and USER C)

:arrow: When User B selects the Kiss All option, all of HER kisses reset to 0



Here's how I am calling this:

The page where User B sees all the options has a link to an external file called "profile-functions.php"

I am using switch to switch between functions.

Here's the code for "profile-functions.php" file

Code: Select all

function kissall($lookup){
		global $db_prefix, $userdata;

		$getkisslist = dbquery("SELECT kisser FROM ".$db_prefix."kiss WHERE kissee='$lookup'");
	
		if(dbrows($getkisslist)) {
			while ($getkldata=dbarray($getkisslist)){
				$kissedb42x2 = dbquery("SELECT kissee FROM ".$db_prefix."kisstracker WHERE kissee='".$getkldata['kisser']."'");
					if (dbrows($kissedb42x2)){
						$kissedb4x2 = dbquery("SELECT kissee,kisser FROM ".$db_prefix."kiss WHERE kissee='".$getkldata['kisser']."' AND kisser='$lookup'");
						if (dbrows($kissedb4x2)==0) {
							dbquery("INSERT INTO ".$db_prefix."kiss VALUES('".$getkldata['kisser']."','".$lookup."','1','0')");
							dbquery("UPDATE ".$db_prefix."kisstracker SET kissee='".$getkldata['kisser']."', k_counter=k_counter+1 WHERE kissee='$lookup'");
						}else{
							dbquery("UPDATE ".$db_prefix."kiss SET kissee='".$getkldata['kisser']."', kisser='$lookup', kiss_counter=kiss_counter+1 WHERE kissee='".$getkldata['kisser']."' AND kisser='$lookup'");
							dbquery("UPDATE ".$db_prefix."kisstracker SET kissee='".$getkldata['kisser']."', k_counter=k_counter+1 WHERE kissee='".$getkldata['kisser']."'");
						}
					} else {
						$kissit = dbquery("INSERT INTO ".$db_prefix."kiss VALUES('".$getkldata['kisser']."','$lookup','1','0')");
						$kissit2 = dbquery("INSERT INTO ".$db_prefix."kisstracker VALUES('".$getkldata['kisser']."','1')");
					}
			}
		dbquery("DELETE FROM ".$db_prefix."kiss WHERE kissee='$lookup'");
		}
				$kickback = "MyAccount.php";
				redirect($kickback);
				return $lookup;
	}
Some function names are guessable as to what they do, however I am going to explain... just in case.

Function addkiss: adds a kiss

Function ackkisses: acknowledges (ignores) the kisses

Function kissall: kisses back to everyone that kissed User B

Function ackkissest: same deal as ackkisses function...except that it returns the user to his/her account page instead of back to profile page.

Function kissback: same deal as addkiss function, except that it returns the user to his/her account page instead of back to the profile page.



There are Two tables used in this "script"

Table 1: is called kiss
Table 2: is called kisstracker

Table kiss has the following fields:
kissee, kisser, kiss_counter, kread

Table kisstracker has two fields:
kissee, k_counter

Table kiss is basically used for "Temporarily" holding who kissed who (until the user who got kissed either ignores or kisses back)
Table kisstracker is used for "PERMENENTLY" holding who got kissed (USER B in our case) and how many times (THE COUNTER)

I tried to use logic in naming the fields....
-kissee is the person who gets kissed
-kisser is who kisses
-kread is set to 0 by default.... if it is 0 only then it will be displayed who kissed USER B when USER B logs in
-others are self-explanatory


My Diagnosis so far:

Here's what I KNOW happens:

When USER B clicks on: "Kiss All" option, all records in table kisstracker where user id of "kissee" is same as USER B turns to the user id of the kisser.... hence ressetting the counter to 0 for User B

Now, after reading all this, do you think I am making this more complex then what it should be?
do you find abnormalities in the kissall function? (because that is the culprit....for sure!!!!! every other function works fine!)

please help.

-Matt

Posted: Fri Jul 21, 2006 7:08 am
by GM
Hi - Can you echo out all the queries that are happening in the kissall function? It's giving me a headache trying to insert the variables into them manually :wink:

If I can see an example of actual queries that are happening, I might be able to help.

Posted: Fri Jul 21, 2006 12:09 pm
by matt1019
Yes, I can echo out all the queries...

Let me be back with the results.


Gimme 5 mins ;)

thanks for your help GM

-Matt

Posted: Fri Jul 21, 2006 12:25 pm
by matt1019
this is my NEW kissall function (with echos)

Code: Select all

function kissall($lookup){
		global $db_prefix, $userdata;

		$getkisslist = dbquery("SELECT kisser FROM ".$db_prefix."kiss WHERE kissee='$lookup'");

		$gkldata = dbarray($getkisslist);
		echo $gkldata['kisser'];
	
		if(dbrows($getkisslist)) {
			while ($getkldata=dbarray($getkisslist)){
				$kissedb42x2 = dbquery("SELECT kissee FROM ".$db_prefix."kisstracker WHERE kissee='".$getkldata['kisser']."'");

				$kb4data = dbarray($kissedb42x2);
				echo $kb4data['kissee'];

					if (dbrows($kissedb42x2)){
						$kissedb4x2 = dbquery("SELECT kissee,kisser FROM ".$db_prefix."kiss WHERE kissee='".$getkldata['kisser']."' AND kisser='$lookup'");

						$kb4xdata = dbarray($kissedb4x2);
						echo $kb4xdata['kissee'];
						echo $kb4xdata['kisser'];

						if (dbrows($kissedb4x2)==0) {
							$anotherq = dbquery("INSERT INTO ".$db_prefix."kiss VALUES('".$getkldata['kisser']."','".$lookup."','1','0')");

						$anotherqdata = dbarray($anotherq);
						echo $anotherqdata;

							$anotherq2 = dbquery("UPDATE ".$db_prefix."kisstracker SET kissee='".$getkldata['kisser']."', k_counter=k_counter+1 WHERE kissee='$lookup'");
						$another2data = dbarray($anotherq2);
						echo $another2data;

						}else{
							$anotherq3 = dbquery("UPDATE ".$db_prefix."kiss SET kissee='".$getkldata['kisser']."', kisser='$lookup', kiss_counter=kiss_counter+1 WHERE kissee='".$getkldata['kisser']."' AND kisser='$lookup'");

						$another3data = dbarray($anotherq3);
						echo $another3data;

							$anotherq4 = dbquery("UPDATE ".$db_prefix."kisstracker SET kissee='".$getkldata['kisser']."', k_counter=k_counter+1 WHERE kissee='".$getkldata['kisser']."'");
						$another4data = dbarray($anotherq4);
						echo $another4data;

						}
					} else {
						$kissit = dbquery("INSERT INTO ".$db_prefix."kiss VALUES('".$getkldata['kisser']."','$lookup','1','0')");
						$kissitdata1 = dbarray($kissit);
						echo $kissitdata1;

						$kissit2 = dbquery("INSERT INTO ".$db_prefix."kisstracker VALUES('".$getkldata['kisser']."','1')");
						$kissitdata2 = dbarray($kissit2);
						echo $kissitdata2;
					}
			}
		$anotherq5 = dbquery("DELETE FROM ".$db_prefix."kiss WHERE kissee='$lookup'");
		$another5data = dbarray($anotherq5);
		echo $another5data;
		}
//				$kickback = "MyAccount.php";
//				redirect($kickback);
				return $lookup;
	}
I have commented out the kickback and rediret lines so that I can see the actual echos

Here was a scenario:

User 7 kissed user 1
User 2 Kissed user 1

User 1 on logging in, saw that he got kissed by 2 users and selected to kiss back both @ the same time (kiss all function).

My echos show the following when executing the kissall function:
72
it is not echoing out the other parts because the conditions are met.... so the function just moves on....

GM: Am I using the correct logic in this? do you have a better logic that you would like to point out?

-Matt