RedZone Posted July 15, 2009 Posted July 15, 2009 I can't get my level system to update my level... I dunno why?? No errors at all... Yes, I have a table called "levels" with manually entered exp and level. function check_level() { global $db, $ir, $userid; $row = $db->fetch_row($db->query('SELECT `level`, `exp` FROM `users` WHERE `userid` = '. $ir['userid'])); $lev = $db->fetch_row($db->query('SELECT `level`, `exp` FROM `levels` WHERE `level` = '. $row['level'])); if($row['exp'] == $lev['exp']) { $db->query("UPDATE `users` SET `level` = `level` + 1 WHERE `userid` = $userid"); } } Quote
Haunted Dawg Posted July 15, 2009 Posted July 15, 2009 Re: Level System function check_level() { global $ir; $row = mysql_query('SELECT `level`,`exp` FROM `users` WHERE `userid` = '.$ir['userid']); $row = mysql_fetch_assoc($row); $lev = mysql_query('SELECT `level`,`exp` FROM `levels` WHERE `level` = '.$row['level']); $lev = mysql_fetch_assoc($lev); if($row['exp'] >= $lev['exp']) { mysql_query('UPDATE `users` SET `level` = `level` + 1 WHERE `userid` = '.$ir['userid']); } } Maybe.. Quote
RedZone Posted July 15, 2009 Author Posted July 15, 2009 Re: Level System Yup, so far it works. :-D Quote
RedZone Posted July 15, 2009 Author Posted July 15, 2009 Re: Level System Okay so when I did more testing on this I noticed that when I level my exp bar jump down to half way... 50% then works its way back up.. I fixed that... but now.. It won't level again?? Help? sorry... :-( function check_level() { global $ir; $row = mysql_query('SELECT `level`,`exp` FROM `users` WHERE `userid` = '.$ir['userid']); $row = mysql_fetch_assoc($row); $lev = mysql_query('SELECT `level`,`exp` FROM `levels` WHERE `level` = '.$row['level']); $lev = mysql_fetch_assoc($lev); if($row['exp'] >= $lev['exp']) { $expu=$row['exp']-$lev['exp']; $row['exp']=$expu; mysql_query('UPDATE `users` SET `level` = `level` + 1, `exp` = $expu WHERE `userid` = '.$ir['userid']); } } Quote
RedZone Posted July 16, 2009 Author Posted July 16, 2009 Re: Level System Sorry for the triple posts but I'm keeping you up to date with what i've changed... I've figured out the problems I think? I just need help with this... The first SQL Update works.. It won't run the next one.... I tried doing in all on one line. When I do that it doesn't update the level then... With this code here... It updates the level fine... Just doesn't set the exp back to 0. function check_level() { global $ir; $row = mysql_query('SELECT `level`,`exp` FROM `users` WHERE `userid` = '.$ir['userid']); $row = mysql_fetch_assoc($row); $lev = mysql_query('SELECT `level`,`exp` FROM `levels` WHERE `level` = '.$row['level']); $lev = mysql_fetch_assoc($lev); if($row['exp'] >= $lev['exp']) { mysql_query('UPDATE `users` SET `level` = `level` + 1, `exp` = `0` WHERE `userid` = '.$ir['userid']); mysql_query('UPDATE `users` SET `exp` = `0` WHERE `userid` = '.$ir['userid']); } } Quote
shedh Posted July 16, 2009 Posted July 16, 2009 Re: Level System Just thinking do you have a table called level? Quote
Haunted Dawg Posted July 16, 2009 Posted July 16, 2009 Re: Level System Just thinking do you have a table called level? He stated in first post. Try adding or die(mysql_error()); to the end of your query's but remmember to remove the ; Quote
CrazyT Posted July 16, 2009 Posted July 16, 2009 Re: Level System Just thinking do you have a table called level? Yeah he does i helped him yestoday do this, but then i felt tired, meh went to bed at 9pm meh got up at half 2pm lol Quote
RedZone Posted July 16, 2009 Author Posted July 16, 2009 Re: Level System Sorry, I forgot to post last night that I fixed it. :-D Thanks guys. Quote
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.