This topic is locked
[SOLVED]

 Scoring system almost there small issue needs sorting

6/8/2012 7:12:57 AM
PHPRunner General questions
S
scoobysteve author

Hi I am creating a scoring system for my members based on content and image uploads etc, the following code works fine by adding the scores into the fields named score1-score11 the total is then worked out by summing these up and then that amount is written to another field TotalScore.
Now its all working in the After successful logon BUT to get the TotalScore updated I have to logon twice with the same userID, I am guessing thst its because after the scores have been written the next piece of code has not successfully obtained the data from the database so returns 0 but then next time it can see the totals, if someone can help I would really appreciate it. Here is the code used
if(!isset($data['Spare2']) || trim($data['Spare2'])==='')

{

global $conn;

$strUpdate = "update tblproperties set score11='0' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}

else

{

global $conn;

$strUpdate = "update tblproperties set score11='100' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}
$DesCount = count(explode(" ",$data['Description']));

global $conn;

$strUpdate = "update tblproperties set score9=$DesCount where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);
$ModsCount = count(explode(" ",$data['ListMods']));

global $conn;

$strUpdate = "update tblproperties set score10=$ModsCount where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);
This is the bit that has to run twice on this event below in order to get the right results
global $conn;

$sum_total = ($data['score9']) + ($data['score10']) + ($data['score11']);

$strUpdate = "update tblproperties set TotalScore=$sum_total where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

S
scoobysteve author 6/8/2012



Hi I am creating a scoring system for my members based on content and image uploads etc, the following code works fine by adding the scores into the fields named score1-score11 the total is then worked out by summing these up and then that amount is written to another field TotalScore.
Now its all working in the After successful logon BUT to get the TotalScore updated I have to logon twice with the same userID, I am guessing thst its because after the scores have been written the next piece of code has not successfully obtained the data from the database so returns 0 but then next time it can see the totals, if someone can help I would really appreciate it. Here is the code used
if(!isset($data['Spare2']) || trim($data['Spare2'])==='')

{

global $conn;

$strUpdate = "update tblproperties set score11='0' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}

else

{

global $conn;

$strUpdate = "update tblproperties set score11='100' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}
$DesCount = count(explode(" ",$data['Description']));

global $conn;

$strUpdate = "update tblproperties set score9=$DesCount where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);
$ModsCount = count(explode(" ",$data['ListMods']));

global $conn;

$strUpdate = "update tblproperties set score10=$ModsCount where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);
This is the bit that has to run twice on this event below in order to get the right results
global $conn;

$sum_total = ($data['score9']) + ($data['score10']) + ($data['score11']);

$strUpdate = "update tblproperties set TotalScore=$sum_total where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);


Any thoughts on this anyone please, I am so close but right now I cant use it until it updates the TotalScore on the first login Thanks Steve

S
scoobysteve author 6/8/2012



Any thoughts on this anyone please, I am so close but right now I cant use it until it updates the TotalScore on the first login Thanks Steve


Its OK i sorted it out with the following.
if(!isset($data['MainImage']) || trim($data['MainImage'])==='')

{

$score1 = 0;

}

else

{

$score1 = 50;

}

if(!isset($data['ADDImage1']) || trim($data['ADDImage1'])==='')

{

$score2 = 0;

}

else

{

$score2 = 100;

}

if(!isset($data['ADDImage2']) || trim($data['ADDImage2'])==='')

{

$score3 = 0;

}

else

{

$score3 = 100;

}

if(!isset($data['ADDImage3']) || trim($data['ADDImage3'])==='')

{

$score4 = 0;

}

else

{

$score4 = 100;

}

if(!isset($data['ADDImage4']) || trim($data['ADDImage4'])==='')

{

$score5 = 0;

}

else

{

$score5 = 100;

}

if(!isset($data['ADDImage5']) || trim($data['ADDImage5'])==='')

{

$score6 = 0;

}

else

{

$score6 = 100;

}

if(!isset($data['ADDImage6']) || trim($data['ADDImage6'])==='')

{

$score7 = 0;

}

else

{

$score7 = 100;

}

if(!isset($data['YouTubeChannel']) || trim($data['YouTubeChannel'])==='')

{

$score8 = 0;

}

else

{

$score8 = 100;

}

if(!isset($data['Spare2']) || trim($data['Spare2'])==='')

{

$score9 = 0;

}

else

{

$score9 = 100;

}
$DesCount = count(explode(" ",$data['Description']));

$score10=$DesCount;
$ModsCount = count(explode(" ",$data['ListMods']));

$score11=$ModsCount;
$total = $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8 + $score9 + $score10 + $score11 ;
global $conn;

$strUpdate = "update tblproperties set TotalScore=$total where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);
if($total >= 200)

{

header("Location: tblproperties_list.php");

}

else

{

header("Location: Profile_List.php");

}

exit();