Bluehost.com Web Hosting $6.95

sum function to string

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-05-2004
Colin Harris
 
Posts: n/a
Default sum function to string

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


Reply With Quote
  #2 (permalink)  
Old 02-05-2004
Andy Hassall
 
Posts: n/a
Default Re: sum function to string

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>
Reply With Quote
  #3 (permalink)  
Old 02-06-2004
Colin Harris
 
Posts: n/a
Default Re: sum function to string


"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:4fi5209j0lnushjrkosi8osr3sg8ftrpii@4ax.com...

Brilliant, thanks Andy!


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:16 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0