Jump to content

Simple problem


paul2463

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/92573-simple-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.