Not updating records correctly & resseting counter to 0
Posted: Thu Jul 20, 2006 6:34 pm
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)
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
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
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)
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;
}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