Stotty Posted December 31, 2008 Share Posted December 31, 2008 On my custom forums im making the Post Count at the Moment In Post.php ive added mysql_query("UPDATE km_users SET posts = '+1' WHERE playername = '$player'"); But when i post the post count goes to one then stops wont go up anymore Why is this ?? Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/ Share on other sites More sharing options...
cpharry Posted December 31, 2008 Share Posted December 31, 2008 You need to add an if function which will get the highest value in the users column for posts and then you run the query that adds one to it. Just putting +1 will set it to literally plus 1. Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/#findComment-726885 Share on other sites More sharing options...
DeanWhitehouse Posted December 31, 2008 Share Posted December 31, 2008 You need to do something like <?php $sql = mysql_query("SELECT posts FROM km_users WHERE playername = '$player'"); $sql = mysql_fetch_assoc($sql); $posts = $sql['posts']; $sql = mysql_query("UPDATE km_users SET posts = '".($posts + 1)."' WHERE playername = '$player'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/#findComment-726887 Share on other sites More sharing options...
Stotty Posted December 31, 2008 Author Share Posted December 31, 2008 Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/#findComment-726893 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 Remember to marked as solved. (Bottom left hand corner.) A quicker way to do this: <?php $sql = mysql_query("UPDATE km_users SET posts = (`posts` + 1) WHERE playername = '$player'"); ?> One statement is a heck of a lot quicker and slicker =) Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/#findComment-726954 Share on other sites More sharing options...
DeanWhitehouse Posted December 31, 2008 Share Posted December 31, 2008 One statement is a heck of a lot quicker and slicker =) Speed difference is hardly noticeable if at all. Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/#findComment-726985 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 One statement is a heck of a lot quicker and slicker =) Speed difference is hardly noticeable if at all. Yea, but there is a difference in speed, however small it is. The main feature is, look how much simpler that is to write than having to go run a query, pull that column assign it to a value then re-use that value in another query to increment it =) Much more efficient and quicker to at least write it. Quote Link to comment https://forums.phpfreaks.com/topic/138989-quick-question/#findComment-726991 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.