Jump to content

Recommended Posts

I am trying to make a point system, but every attempt fails miserably, could someone help me?

 

I pull the points for the user from the DB, then I pull the point values from the DB as well.

Then I pull the winners, and the user picks from the database as well.

 

Now I take the information and create a IF statement I say

if $userpick === $winnner{

$total = $value + $rnd1;

}else{

do not add and continue to the next pick.

 

There are 32 chances to earn points, but it does not work at all.

 

Also I have multiple users on the website, so would I have to do a loop? I want this to run after the admin makes the selection for the winners.

 

Could just someone give me an example code?

 

-Thanks

Link to comment
https://forums.phpfreaks.com/topic/92844-point-system/
Share on other sites

Oh ya that would be a good idea

 

in the first IF statment, if the winner does not equal userpick, it does not add the points for the next if statment.

 

<?php
include("style/include/session.php");
include ("style/include/cons/head.php");
echo '<div class="box">';
if($session->logged_in){
$user = $session->username;

   /*Pull Winners for Round 1*/
  $q = mysql_query("Select * from `rnd1_win`");
  $win=mysql_fetch_array($q);
   
  /*Pull User Picks for Round 1*/
  $q = mysql_query("Select * from `rnd1`");
  $pick=mysql_fetch_array($q);
  
  /*Pull Point Values for Round 1*/
  $q = mysql_query("Select * from `points`");
  $point=mysql_fetch_array($q);
  $value = $point['0'];
  
  /*Pull User Points for Round 1*/
  $q = mysql_query("Select * from `userpoints`");
  $usrpoint=mysql_fetch_array($q);
  $total = $usrpoint['total'];
  $rnd1 = $usrpoint['1'];
  
  
  
  if ($win['0'] === ($pick['a1'])){
   $total = $value + $total;
   $rnd1 = $value + $rnd1;
   $q = "UPDATE `userpoints` SET `total`=$total WHERE `username`='$user'";
       mysql_query($q);
   $q = "UPDATE `userpoints` SET `1`=$rnd1 WHERE `username`='$user'";
       mysql_query($q);
   }else{
   
  if ($win['1'] === ($pick['a2'])){
   $total = $value + $total;
   $rnd1 = $value + $rnd1;
   $q = "UPDATE `userpoints` SET `total`=$total WHERE `username`='$user'";
       mysql_query($q);
   $q = "UPDATE `userpoints` SET `2`=$rnd1 WHERE `username`='$user'";
       mysql_query($q);
   }
   
   
   echo "<h2>Point Test</h2>";
   echo "<p>Your Total: $total<br>";
   echo "Your Round 1: $rnd1</p>";
  }
  
}else{
include ("style/include/cons/member.php");
}
print '</div>';
include ("style/include/cons/foot.php");
  
?>

Link to comment
https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475608
Share on other sites

if ( $win['0'] == $pick['a1'] )
{
    $total = $value + $total;
    $rnd1 = $value + $rnd1;
    mysql_query("UPDATE `userpoints` SET `total`='$total', `1`='$rnd1' WHERE `username`='$user'");

} else if ( $win['1'] == $pick['a2'] )
{
    $total = $value + $total;
    $rnd1 = $value + $rnd1;
    mysql_query("UPDATE `userpoints` SET `total`='$total', `2`='$rnd1' WHERE `username`='$user'");
}

Link to comment
https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475785
Share on other sites

You do realise that doing

/*Pull Winners for Round 1*/
  $q = mysql_query("Select * from `rnd1_win`");
  $win=mysql_fetch_array($q);
[code]

You are selecting ALL the rows from the table rnd1_win, with NO ordering, and thus you cannot guarantee which result you are pulling out using mysql_fetch_array. You are pulling the top one that MySQL presents to you (which is unknown). I suggest you work out what your SQL statements should be because this could well be a big flaw in the data you think you're pulling.

[/code]

Link to comment
https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475789
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.