paul2463 Posted February 23, 2008 Share Posted February 23, 2008 hi guys I realise this might be a simple problem and the answer is staring me in the face, I can manage what i need through PHP however it would be easier for me if the data was pulled in the query. I will simplify the table makeup to try and make the problem easier. I have 1 table lets call it golfballs, it has four columns (white , orange, green, red) and each column stores the number of each colour golf ball that each golfer has. now I also have a requirement for knowing the total number of all coloured golfball the golfer has, this is dynamic data and is therefore not stored in the table but calculated, as I said I can do it through PHP by simple query and then adding all numbers together to get the total so the query would be $query = "SELECT `white` , `orange`, `green`, `red` FROM golfballs WHERE golfer is '$golfer'"; // then i iterate through the row and calculate the toal number of balls what I would like to do is something like $query = "SELECT `white` , `orange`, `green`, `red` SUM(`white` , `orange`, `green`, `red`) AS totalgb FROM golfballs WHERE golfer is '$golfer'"; many thank sin advance to all help proffered Quote Link to comment https://forums.phpfreaks.com/topic/92573-simple-problem/ Share on other sites More sharing options...
paul2463 Posted February 23, 2008 Author Share Posted February 23, 2008 I have managed this, although not very elegant and my normal table has about 12 columns in it SELECT `white` , `orange` , `green` , `red` , `white` + `orange` + `green` + `red` AS totalgb Quote Link to comment https://forums.phpfreaks.com/topic/92573-simple-problem/#findComment-474389 Share on other sites More sharing options...
fenway Posted February 23, 2008 Share Posted February 23, 2008 Hi paul... long time no see! Not elegant? That's the only way to add values. Quote Link to comment https://forums.phpfreaks.com/topic/92573-simple-problem/#findComment-474479 Share on other sites More sharing options...
paul2463 Posted February 24, 2008 Author Share Posted February 24, 2008 thanks for the reply Fenway, as helpful as ever I have been around just lurking and helping on simple problems ( PHP mainly) trying to find a new job which is taking up all my time and patience Quote Link to comment https://forums.phpfreaks.com/topic/92573-simple-problem/#findComment-474995 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.