muddy004 Posted January 9, 2008 Share Posted January 9, 2008 Dear Freaks, This is an odd question. I've inherited a very old php application. I attempted to upgrade it. The application is used to add certain columns of data. On the original server, three columns add just fine (output to a report). On the upgraded server (newer mysql and php), the report displays zero for the three columns. This is the code for adding the three columns: # locations $sql_locs = "SELECT sum(C1NearHome)+sum(C2NearHome)+sum(C3NearHome), sum(C1NearWork)+sum(C2NearWork)+sum(C3NearWork), sum(C1NearSchool)+sum(C2NearSchool)+sum(C3NearSchool) FROM request WHERE YMDHMS >= $bgnDate AND YMDHMS <= $endDate"; $res_locs = mysql_query($sql_locs); $nrow_locs = mysql_num_rows($res_locs); if ($nrow_locs > 0) { $row_locs = mysql_fetch_row($res_locs); $stats[$stindx . "nearHome"] = $row_locs[0]; $stats[$stindx . "nearWork"] = $row_locs[1]; $stats[$stindx . "nearSchool"] = $row_locs[2]; } This line: sum(C1NearSchool)+sum(C2NearSchool)+sum(C3NearSchool) isn't adding correctly. The report on the new server shows zero, but on the old server, for example, the number is 4. If I remove two of the sums and make it: sum(C1NearSchool) the report displays the total for that column. When I add the two other sums back to the equation, I get zero again. Any ideas what's wrong here? Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/85191-simple-sum-not-working/ Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Maybe try something like.. $sql_locs = "SELECT (sum(C1NearHome)+sum(C2NearHome)+sum(C3NearHome)), (sum(C1NearWork)+sum(C2NearWork)+sum(C3NearWork)), (sum(C1NearSchool)+sum(C2NearSchool)+sum(C3NearSchool)) FROM request WHERE YMDHMS >= $bgnDate AND YMDHMS <= $endDate"; If that doesn't work, post in the MySQL forum, Fenway probably knows. Quote Link to comment https://forums.phpfreaks.com/topic/85191-simple-sum-not-working/#findComment-434626 Share on other sites More sharing options...
clearstatcache Posted January 10, 2008 Share Posted January 10, 2008 how about this... $sql_locs = "SELECT sum(C1NearHome+C2NearHome+C3NearHome), sum(C1NearWork+C2NearWork+C3NearWork), sum(C1NearSchool+C2NearSchool+C3NearSchool) FROM request WHERE YMDHMS >= $bgnDate AND YMDHMS <= $endDate"; Quote Link to comment https://forums.phpfreaks.com/topic/85191-simple-sum-not-working/#findComment-435133 Share on other sites More sharing options...
muddy004 Posted January 22, 2008 Author Share Posted January 22, 2008 Thank for the try. Unfortunately, these fixes didn't work. I'll try the mysql forums. thanks Quote Link to comment https://forums.phpfreaks.com/topic/85191-simple-sum-not-working/#findComment-446273 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.