This is a discussion on sum function to string within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Guys, another problem for you: I'd now like to do a 'standings' page, where I take the driver's ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Guys, another problem for you: I'd now like to do a 'standings' page, where
I take the driver's name, add up his points and echo it. Below is the MySQL query, which works fine, but I can't remember how to copy the data from sum(points) to the string $points. Can someone help? SELECT driver, sum( points ) FROM drivers, exports WHERE drivers.driver_id = exports.driver_id GROUP BY ( drivers.driver_id ) ORDER BY 'sum(points)' while($data = mysql_fetch_array($result)) { $driver = $data["driver"]; $points =$data the sum of the points // I tried $points=["sum(points)"] but that didn't work Thanks, sorry to bother you, and if I *AM* bothering you, could you tell me the right forum/newsgroup to go to? Colin |
|
|||
|
On Thu, 5 Feb 2004 21:54:34 -0000, "Colin Harris"
<c_harris01@getridofthisbit.blueyonder.co.uk> wrote: >Guys, another problem for you: I'd now like to do a 'standings' page, where >I take the driver's name, add up his points and echo it. Below is the MySQL >query, which works fine, but I can't remember how to copy the data from >sum(points) to the string $points. Can someone help? > > >SELECT driver, sum( points ) Add an alias for convenience here: SELECT driver, sum( points ) total_points >FROM drivers, exports >WHERE drivers.driver_id = exports.driver_id >GROUP BY ( >drivers.driver_id >) >ORDER BY 'sum(points)' Doesn't do what you think, that's ordering by the literal string sum(points). Remove the quotes. >while($data = mysql_fetch_array($result)) { >$driver = $data["driver"]; >$points =$data the sum of the points // I tried $points=["sum(points)"] With the alias above, you can now use $data['total_points'] -- Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool <http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space> |