Lamez Posted February 25, 2008 Share Posted February 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/ Share on other sites More sharing options...
cunoodle2 Posted February 25, 2008 Share Posted February 25, 2008 Please post the existing code you have thus far and we will work with you to get it in better working order. Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475605 Share on other sites More sharing options...
Lamez Posted February 25, 2008 Author Share Posted February 25, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475608 Share on other sites More sharing options...
Lamez Posted February 25, 2008 Author Share Posted February 25, 2008 also, I need this to work after I have selected the winners, and update ever user in the system point values. Do I need loop? If so how? Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475610 Share on other sites More sharing options...
Lamez Posted February 25, 2008 Author Share Posted February 25, 2008 bump for the night Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475630 Share on other sites More sharing options...
Lamez Posted February 25, 2008 Author Share Posted February 25, 2008 am I doing the IF statement right? Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475783 Share on other sites More sharing options...
Chris92 Posted February 25, 2008 Share Posted February 25, 2008 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'"); } Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475785 Share on other sites More sharing options...
aschk Posted February 25, 2008 Share Posted February 25, 2008 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] Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-475789 Share on other sites More sharing options...
Lamez Posted February 25, 2008 Author Share Posted February 25, 2008 well noted. I think I have it down now, I am not sure, but how do I do a loop? I know I would have to pull the user names from user table, I would have to make the loop run for ever user in the user table, but how? Quote Link to comment https://forums.phpfreaks.com/topic/92844-point-system/#findComment-476316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.