Lamez Posted March 3, 2008 Share Posted March 3, 2008 Alright I have this code, it is suppose to check to see if the pick is not equal to emp, if not then it checks to see if there is a zero in the respective field in the database, if so then it checks to see if the user picked the winner, and if so it add points, then it adds a 1 to the database, so no user can get points for that round again once the script is run again, but it is not adding a one, could someone look over the code for any errors: <?php $result=mysql_query('SELECT * FROM userpoints'); while($row=mysql_fetch_array($result)){ $user=$row['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` Where `username` = '$user'"); $pick=mysql_fetch_array($q); /*Pull Point Values for Round 1*/ $q = mysql_query("Select rnd1 from `points`"); $point=mysql_fetch_array($q); $value = $point['rnd1']; /*Pull User Points for Round 1*/ $q = mysql_query("Select `username`, `total`, `rnd1` from `userpoints` Where `username` = '$user'"); $usrpoint=mysql_fetch_array($q); $total = $usrpoint['total']; $rnd1 = $usrpoint['rnd1']; /*Pull Info from check table*/ $qu = "SELECT * FROM `rnd1_check`"; $re = mysql_query($qu); $ck = mysql_fetch_array($re); if (!$pick['a1'] === ("emp")){ if ($ck['r1'] === ("0")){ if ($win['1'] === ($pick['a1'])){ $total = $value + $total; $rnd1 = $value + $rnd1; mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); mysql_query("UPDATE `rnd1_check` SET `r1`='1' WHERE `id`='1'")or die (mysql_error()); } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/ Share on other sites More sharing options...
cooldude832 Posted March 3, 2008 Share Posted March 3, 2008 why are u using === for comparisons to some strange things? from your post you say you want to 1) Check if Pick is not empty 2) check if there is no zero in the respective row of pick (if not empty) 3) Check if winner is picked in that row 4) If 3 is true +1 to points and either way for 3 Make that row marked off as voted. so how I do it [code] <?php $picks_table = "picks"; $winners_table = "winners"; $users_table = "userpoints"; if($_POST['Pick'] != "emp"){ $pickid = mysql_real_escape_string(intval($_POST['Pick'])); #Check to make sure row isn't selected already, while we're querying lets also get the winner and user pick (save 2 queries) $q = " Select ".$picks_table.".ZEROFIELD as zero, ".$picks_table.".PICKEDWINNER as User_pick, ".$winners_table.".winning_team as winner ".$picks_table.".PICKER as UserID from `".$picks_table."`, `".$winners_table."` where ".$picks_table.".GAMEID = ".$winners_table.".GAMEID and ".$picks_table.".pickid = ".$pickid." group by ".$picks_table.".pickid "; $r = mysql_query($q) or die(mysql_error()); #We should have 1 and only row since pickid is unique $row = mysql_fetch_assoc($r); if($row['zero'] != 0){ #The row isn't graded yet if($row['User_pick'] == $row['winner']){ #They picked properly so lets add a count $q = "update `".$users_table."` CORRECT_PICKS_COUNT = CORRECT_PICKS_COUNT+1 where UserID = '".$row['UserID']."'"; $r = mysql_query($q) or die(mysql_error()); } #Need to check of that row so say $q = "Update `".$picks_table."` set CHECKEDOFF = '1' where UserID = '".$row['UserID']."'"; $r = mysql_query($q) or die(mysql_error()); } } ?> now I didn't put in your fields on purpose so you can read it through and see how to do things the right way. [/code] Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482161 Share on other sites More sharing options...
Lamez Posted March 3, 2008 Author Share Posted March 3, 2008 I am not too sure if that code is going to work, and here is why: This is on the admin side, the admin will choose the round winners, then the script will change the post variables into easy to remember to variables ($a1 = $_POST['1a'], then it will update the round winners into rnd1_win, then it runs a included file called pnts_1.php, this file has a loop, it checks ever user to see if they have chosen the winner, but on the admin side, the admin can make changes to the winners in that round, because there are more than one game in the round, so he needs to be able to update it, so the script side it checks the table for a 1 to see if that team win has been processed, if not then it process it, then adds a one to the db. well here is the first page of the script: <?php include ("../../../style/include/session.php"); include ("../../../style/include/cons/head_3.php"); if($session->isAdmin()){ $a1 = $_POST['a1']; $a2 = $_POST['a8']; $a3 = $_POST['a5']; $a4 = $_POST['a4']; $a5 = $_POST['a6']; $a6 = $_POST['a3']; $a7 = $_POST['a7']; $a8 = $_POST['a2']; $b9 = $_POST['b1']; $b10 = $_POST['b8']; $b11 = $_POST['b5']; $b12 = $_POST['b4']; $b13 = $_POST['b6']; $b14 = $_POST['b3']; $b15 = $_POST['b7']; $b16 = $_POST['b2']; $c17 = $_POST['c1']; $c18 = $_POST['c8']; $c19 = $_POST['c5']; $c20 = $_POST['c4']; $c21 = $_POST['c6']; $c22 = $_POST['c3']; $c23 = $_POST['c7']; $c24 = $_POST['c2']; $d25 = $_POST['d1']; $d26 = $_POST['d8']; $d27 = $_POST['d5']; $d28 = $_POST['d4']; $d29 = $_POST['d6']; $d30 = $_POST['d3']; $d31 = $_POST['d7']; $d32 = $_POST['d2']; $q = "UPDATE `rnd1_win` SET `1` = '$a1', `2` = '$a2', `3` = '$a3', `4` = '$a4', `5` = '$a5', `6` = '$a6', `7` = '$a7', `8` = '$a8', `9` = '$b9', `10` = '$b10', `11` = '$b11', `12` = '$b12', `13` = '$b13', `14` = '$b14', `15` = '$b15', `16` = '$b16', `17` = '$c17', `18` = '$c18', `19` = '$c19', `20` = '$c20', `21` = '$c21', `22` = '$c22', `23` = '$c23', `24` = '$c24', `25` = '$d25', `26` = '$d26', `27` = '$d27', `28` = '$d28', `29` = '$d29', `30` = '$d30', `31` = '$d31', `32` = '$d32' WHERE `id` = '1'"; mysql_query($q) or die(mysql_error()); include ("pnt_1.php"); print '<div class="box"><h2>Winners Updated</h2>'; print '<p>Winners Updated for Round 2<br><br>'; print '<a href="slcwin_1.php">Round 2</a></p>'; print '</div>'; }else{ header("Location: ../../../index.php"); } include ("../../../style/include/cons/foot.php"); ?> here is pnt_1.php <?php include ("../../../style/include/session.php"); $result=mysql_query('SELECT * FROM userpoints'); while($row = mysql_fetch_array($result)){ $user = $row['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` Where `username` = '$user'"); $pick=mysql_fetch_array($q); /*Pull Point Values for Round 1*/ $q = mysql_query("Select rnd1 from `points`"); $point=mysql_fetch_array($q); $value = $point['rnd1']; /*Pull User Points for Round 1*/ $q = mysql_query("Select `username`, `total`, `rnd1` from `userpoints` Where `username` = '$user'"); $usrpoint=mysql_fetch_array($q); $total = $usrpoint['total']; $rnd1 = $usrpoint['rnd1']; /*Pull Info from check table*/ $q = mysql_query("SELECT * FROM `rnd1_check`")or die(mysql_query()); $ck = mysql_fetch_array($q)or die(mysql_query()); if ($ck['r1'] === ("0")){ if (!$pick['a1'] === ("emp")){ if ($win['1'] === ($pick['a1'])){ $total = $value + $total; $rnd1 = $value + $rnd1; mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); mysql_query("UPDATE `rnd1_check` SET `r1`='1' WHERE `id`='1'")or die (mysql_error()); } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482168 Share on other sites More sharing options...
cooldude832 Posted March 3, 2008 Share Posted March 3, 2008 so you want to have the admin after the post a the "winner" update all wins for that round? does your table store the roundID for what the admin is updating? if so you can probably do a conditional querying that be like update `players_points`, `pickstable` set if(pickstable.pick == winnerstable.winner){players_points.points++}, pickstable.Scored = '1' where RoundID = $_POST['Round'] Not sure on the exact syntax but basically that should do it for you in 1 swoop. It will check if they have a winner if show up the point total by 1 and then no matter what set the scored value to 1 for every row in that "round" Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482170 Share on other sites More sharing options...
Lamez Posted March 3, 2008 Author Share Posted March 3, 2008 all the code works fine, it just does not add a 1 to the db, and I have no idea why. is there something wrong with my if statements? my query's? I do not understand why it is not adding a 1 to r1 under rnd1_check Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482171 Share on other sites More sharing options...
cooldude832 Posted March 3, 2008 Share Posted March 3, 2008 I'm just trying to save you work down the road so you have it working on a properly built DB to run simpler quires but your issue is look at $total and tell me what $value is $total = 0 from what I see so thus you are adding $total to it if they are right which is 0 so its like doing nothing Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482174 Share on other sites More sharing options...
Lamez Posted March 3, 2008 Author Share Posted March 3, 2008 well let me break down this code for you: if ($ck['r1'] === ("0")){ this line here checks to see if there is a 0 instead of a one if so continue if (!$win['a1'] === ("emp")){ this line checks to see if the admin made a selection on this field, if he has, the selection will not be emp, it will be somthing else if ($win['1'] === ($pick['a1'])){ this line here check to see if the user picked the winner, if so it will add points which are on the next 2 lines $total = $value + $total; this line here will take their current total, and add the point value, the admin has setup, and will give them a new total $rnd1 = $value + $rnd1; this line here takes the their current total in rnd1 and will add the point value the admin has setup, and give them a new value mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); this line updates the db, with rnd1 and total where there username is mysql_query("UPDATE `rnd1_check` SET `r1`='1' WHERE `id`='1'")or die (mysql_error()); this line gives me trouble, it adds a one to the database so this round, so the round could not be ran again. } } closes the if statments } Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482184 Share on other sites More sharing options...
cooldude832 Posted March 3, 2008 Share Posted March 3, 2008 still don't see the initialization of $value making those two lines with it pointless. Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482186 Share on other sites More sharing options...
Lamez Posted March 3, 2008 Author Share Posted March 3, 2008 I am not too sure on what you are asking, the value is set here, on these lines: <?php /*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` Where `username` = '$user'"); $pick=mysql_fetch_array($q); /*Pull Point Values for Round 1*/ $q = mysql_query("Select rnd1 from `points`"); $point=mysql_fetch_array($q); $value = $point['rnd1']; /*Pull User Points for Round 1*/ $q = mysql_query("Select `username`, `total`, `rnd1` from `userpoints` Where `username` = '$user'"); $usrpoint=mysql_fetch_array($q); $total = $usrpoint['total']; $rnd1 = $usrpoint['rnd1']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482191 Share on other sites More sharing options...
Lamez Posted March 3, 2008 Author Share Posted March 3, 2008 would the triple equal signs have any effect? should I change them to just 2 equal signs? Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482204 Share on other sites More sharing options...
Lamez Posted March 3, 2008 Author Share Posted March 3, 2008 maybe posting this will help: <?php $winner = $win['1']; $check = $ck['r1']; $a = $a1; $b = $a16; $var = "a1"; if ($check === ("0")){ echo "<select name=".$var.">"; echo '<option value="emp"></option>'; echo '<option value="'.$a.'">'.$a.'</option>'; echo '<option value="'.$b.'">'.$b.'</option>'; echo '</select>'; }else{ echo $winner; echo '<input name="'.$var.'" type="hidden" id="'.$var.'" value="'.$winner.'" />'; } ?> any errors there? Quote Link to comment https://forums.phpfreaks.com/topic/94125-what-is-the-problem-been-on-this-for-weeks-now/#findComment-482229 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.