Nexus Zero Posted July 29, 2007 Share Posted July 29, 2007 This following code snippet successfully takes a specific entry from the "comments" table and dumps it into the $row array. The 'if' statement looks at a $_GET value which, if set to 'up', takes an integer from this array, increases it, and is meant to write it back to the database. While the code does increase this integer (revealed when using echo lines), it doesn't seem to write the number back to the database, or if it does, not in the right place. $result = mysql_query("SELECT * FROM comments WHERE commentsID=$commentsid"); $row = mysql_fetch_array($result); if($judgement=="up") { $insert = $row['Rank']++; mysql_query("INSERT INTO comments ('Rank') VALUES ($insert)"); Any help will be much appreciated! Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2007 Share Posted July 29, 2007 try $insert = ++$row['Rank']; $var++ returns value then increments Quote Link to comment Share on other sites More sharing options...
Nexus Zero Posted July 29, 2007 Author Share Posted July 29, 2007 Thanks for the quick reply. Unfortunately, that didn't seem to work either. After the increment, both $insert and $row['Rank'] are 1 (as opposed to 0 before). It's a matter of writing it to the database in the correct way, though I don't see what's going wrong. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2007 Share Posted July 29, 2007 result = mysql_query("SELECT * FROM comments WHERE commentsID=$commentsid"); $row = mysql_fetch_array($result); if($judgement=="up") { mysql_query("UPDATE comments SET Rank = Rank + 1 WHERE commentsID=$commentsid"); } Quote Link to comment Share on other sites More sharing options...
Nexus Zero Posted July 29, 2007 Author Share Posted July 29, 2007 That's fantastic, works perfectly and I've learned a little something too Many thanks. 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.