I need to add a column to a mysql database. This should be fairly simple but I have never seen it done before where the values in the new column are based on the values in the other columns and the variables that have previously been defined in the php.
Unfortunately, the variable averagepolar will be different each time this script is carried out. Therefore the new column will have different values everytime the script is run.
Maybe I am using a elephant gun to kill a mouse but I need to return the values of the new column ordered in ascending order. If I just simply multiply them individually (row by row) then I can't sort them, so I came up with the idea of creating a new column and sorting that.
I'm happy for someone to correct me if this is the wrong thing to do. I also tried using usort() but could not get this to work.
mysql_query("update solvents set Red = ".$row['Polar']." * $averagepolar");
depending on preference. You cannot output arrays in an output string like you can normal variables.
I would have to also question the basic database design if you are having to add columns using php. Normally you would have another table storing Red,Yellow, whatever with possibly a joining table sovent2colour. (Without seeing exactly what you are trying to do this is difficult to judge).
pyoungson wrote:Unfortunately, the variable averagepolar will be different each time this script is carried out. Therefore the new column will have different values everytime the script is run.
Maybe I am using a elephant gun to kill a mouse but I need to return the values of the new column ordered in ascending order. If I just simply multiply them individually (row by row) then I can't sort them, so I came up with the idea of creating a new column and sorting that.
I'm happy for someone to correct me if this is the wrong thing to do. I also tried using usort() but could not get this to work.
OK ...
1. averagepolar is a constant - so you may order by Polar field.
2. You can use math operations directly into SQL query - think about it.
There are 10 types of people in this world, those who understand binary and those who don't