i have been looking all over the place, but i need to know how to create a field in my database table that simply adds two of the other fields?
what datatype.
i tried VARCHAR length 5 values 'field_one'+'field_two'
what is the correct syntax?
-Michael
So, let me get this straight. What you want to do is to merge the values in "field_one" and "field_two" into a new field in your table? I don't think that you can do this with just one query, I think that you have to add the field with one query and then update the table with another one.
// add the field $sql = "ALTER TABLE tbl_name ADD field_three VARCHAR(10)"; mysql_query($sql) or die(mysql_error()); // update the table $sql = "UPDATE tbl_name SET field_three = CONCAT(field_one, field_two)"; mysql_query($sql) or die(mysql_error());
/ Erik
Just add them together in the SELECT query i.e.:
SELECT field1 + field2 AS total FROM table
So if you want to query field1, field2, and their total it would be:
SELECT field1,field2,field1 + field2 AS total FROM table