peterisgb Posted February 19, 2013 Share Posted February 19, 2013 hello i need a little help with a sql which i'm not quite understand. could i have some help $db->query("UPDATE users SET sides=sides+1 WHERE userid={$ir['userid']}",$c); This is what i got so far, how would i get this formula to work like this sides +1 if (userid % 2) = 0"); and (userid % 2) <> 0"); so you only get a +1 if you are odd ID attacking Even ID and same vice versa. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted February 19, 2013 Author Share Posted February 19, 2013 well in ODD userid attacks a EVEN user ID then that user will get a +1, and if an EVEN id attacks a ODD user id they get a +1 but if a EVEN ID user attacks and EVEN user id they dont get a +1 same with ODD attacking ODD Its battles with good and evil. odds being evil and even id are good, that system is there now but i cant figure this line out to add to attackwon.php etc. Quote Link to comment Share on other sites More sharing options...
sniko Posted February 19, 2013 Share Posted February 19, 2013 /* I'm using $r, but preferably I'd use the query string */ if( ((($ir['userid'] % 2) == 0) AND (($r['userid'] % 2) != 0)) OR ((($ir['userid'] % 2) != 0) AND (($r['userid'] % 2) == 0)) ) { /* Plus one. */ } /* No need to put in code to not plus 1 */ Quote Link to comment Share on other sites More sharing options...
peterisgb Posted February 19, 2013 Author Share Posted February 19, 2013 (edited) so if i'm right like this? $db->query("UPDATE users SET sides=sides+1 WHERE userid={$ir['userid']} AND ((($ir['userid'] % 2) != 0)) AND (($r['userid'] % 2) == 0))) ",$c); or like this $db->query("UPDATE users SET sides=sides+1 WHERE userid=$userid AND (($ir['userid'] % 2) != 0))",$c); $db->query("UPDATE users SET sides=sides+1 WHERE userid=$userid AND (($r['userid'] % 2) == 0))",$c); or is that wrong. Edited February 19, 2013 by peterisgb Quote Link to comment Share on other sites More sharing options...
sniko Posted February 19, 2013 Share Posted February 19, 2013 Do the following; /* * For attackwon, and other won outcomes I'm using $r, but preferably I'd use the query string */ if( ((($ir['userid'] % 2) == 0) AND (($r['userid'] % 2) != 0)) OR ((($ir['userid'] % 2) != 0) AND (($r['userid'] % 2) == 0)) ) { $db->query("UPDATE `users` SET `sides`=`sides`+1 WHERE `userid`={$userid}", $c); } /* * For attacklost, and other lost outcomes I'm using $r, but preferably I'd use the query string */ if( ((($ir['userid'] % 2) == 0) AND (($r['userid'] % 2) != 0)) OR ((($ir['userid'] % 2) != 0) AND (($r['userid'] % 2) == 0)) ) { $db->query("UPDATE `users` SET `sides`=`sides`+1 WHERE `userid`={$r['userid']}", $c); } In theory, that should work how you require it to. Also, to get the winning side, just count the values of sides for each side ;) Quote Link to comment Share on other sites More sharing options...
peterisgb Posted February 19, 2013 Author Share Posted February 19, 2013 i'll tset it out and get back with the resaults Quote Link to comment Share on other sites More sharing options...
peterisgb Posted February 22, 2013 Author Share Posted February 22, 2013 thanks it worked like a charm, just another little help The default userlist pages, is there a way i can create another userlist and get it to display only Odd ID's or Even ID's? Quote Link to comment Share on other sites More sharing options...
Djkanna Posted February 23, 2013 Share Posted February 23, 2013 thanks it worked like a charm, just another little help The default userlist pages, is there a way i can create another userlist and get it to display only Odd ID's or Even ID's? Depends on how you want to do it. <?php $query = 'SELECT `username` FROM `users` WHERE ( `userid` % 2 = '.( array_key_exists ( 'odd', $_GET ) ? 1 : 0 ).' )'; echo '<a href="userlist.php" title="Even users">Even users</a>‐<a href="userlist.php?odd" title="Odd users">Odd Users</a>'; //Execute query & do whatever else you wish to do. May work. Quote Link to comment 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.