Mutley Posted December 18, 2006 Share Posted December 18, 2006 I'm trying to add a value to a database, depending on the comparison of 2 values.So:if($value1 > $value2) {...insert value3 into the database.The value1 and value2 will also be in the database. So is something like this correct:[code]<?php"SELECT value1, value2 FROM table1";$result = mysql_query($sql);$value1 = "$_GET['value1']";$value2 = "$_GET['value2']";if($value1 > $value2) {$value3 = "Yes";} else {$value3 = "No";}INSERT INTO `table1` (value3) VALUES ('".$value3."');?>[/code]I'm really not very good at the lines of code to insert/view database but it's hopefully enough for some idea on what I'm trying to do. Link to comment https://forums.phpfreaks.com/topic/31094-add-value-to-database-if-maths/ Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 Try something like this:[code]<?php// Query the database for the values$sql = "SELECT value1, value2 FROM table1"; // unless you only have one row you'll want a WHERE clause here$result = mysql_query($sql);$row = mysql_fetch_array($result);// Check the values and assign accordinglyif ($row['value1'] > $row['value2']){ $value3 = "Yes";}else { $value3 = "No";}// Insert new data into the database$sql = "INSERT INTO `table1` (value3) VALUES ('$value3')"; // Again, if using a WHERE clause, you'll want it here too.$mysql_query($sql);?>[/code]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/31094-add-value-to-database-if-maths/#findComment-143549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.