MadnessRed Posted June 24, 2008 Share Posted June 24, 2008 OK, I am still very new to this kinda thing. What i want to do is, add a number to an already existing number. Eg, if in the database it said 9, I could add 5 more to that. Is there a simple way to do this, or do I find the old value, add the new value to it, then write it, or can I just add it? Here is an example $old = $row['Description']; $plus = $_GET["plus"]; $new = $old + $plus; $query1 = "UPDATE `madnessred_sites` SET `Count` = '$new' WHERE `ID` ='$id'"; Could I instead do something like $query1 = "UPDATE `madnessred_sites` ADD TO `Count` = '$new' WHERE `ID` ='$id'"; Link to comment https://forums.phpfreaks.com/topic/111740-solved-add-to-a-database-value-noob-question/ Share on other sites More sharing options...
Barand Posted June 24, 2008 Share Posted June 24, 2008 $query1 = "UPDATE `madnessred_sites` SET `Count` = `Count` + $plus WHERE `ID` = '$id'"; Link to comment https://forums.phpfreaks.com/topic/111740-solved-add-to-a-database-value-noob-question/#findComment-573638 Share on other sites More sharing options...
MadnessRed Posted June 24, 2008 Author Share Posted June 24, 2008 thanks also for a slightly different code, would this work $query1 = "UPDATE `madnessred_sites` SET `Count` = `Count` + '1' WHERE `ID` = '$id'"; Link to comment https://forums.phpfreaks.com/topic/111740-solved-add-to-a-database-value-noob-question/#findComment-573639 Share on other sites More sharing options...
Barand Posted June 25, 2008 Share Posted June 25, 2008 yes. the quotes round '1' are unnecessary though as it's a numeric value Link to comment https://forums.phpfreaks.com/topic/111740-solved-add-to-a-database-value-noob-question/#findComment-573904 Share on other sites More sharing options...
MadnessRed Posted June 25, 2008 Author Share Posted June 25, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/111740-solved-add-to-a-database-value-noob-question/#findComment-574087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.