egiblock Posted June 19, 2009 Share Posted June 19, 2009 i have a table. colums y1,y2,y3,y4 .... i want a total called YardsOut so i can display it on the site: $query_CourseDetail = "select * from tbl_courses WHERE $id = tbl_courses.courseID"; $CourseDetail = mysql_query($query_CourseDetail, $golfscoring) or die(mysql_error()); $row_CourseDetail = mysql_fetch_assoc($CourseDetail); $totalRows_CourseDetail = mysql_num_rows($CourseDetail); $YardsOut = $row_CourseDetail['y1']+$row_CourseDetail['y2']; echo $YardsOut; is there a easier way to get the totals ? Quote Link to comment Share on other sites More sharing options...
akitchin Posted June 19, 2009 Share Posted June 19, 2009 you could select the sum directly: SELECT (y1 + y2) AS yardsTotal FROM tbl_courses WHERE courseID = $id after running the query and grabbing the result, 'yardsTotal' should contain the sum. Quote Link to comment Share on other sites More sharing options...
egiblock Posted June 20, 2009 Author Share Posted June 20, 2009 you could select the sum directly: SELECT (y1 + y2) AS yardsTotal FROM tbl_courses WHERE courseID = $id after running the query and grabbing the result, 'yardsTotal' should contain the sum. so i tried the following: $sql = "SELECT (y1 + y2) AS yardsTotal FROM tbl_courses WHERE courseID = $id"; $yardstotal = mysql_query($sql, $golfscoring); echo $yardstotal; and got: Resource id #536 sorry, but this is my first time with php and databases, especially mysql.. in the past i've always used coldfusion with access. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 <?php $result = mysql_fetch_assoc($yardstotal); echo $result['yardsTotal']; Quote Link to comment Share on other sites More sharing options...
egiblock Posted June 21, 2009 Author Share Posted June 21, 2009 here's what i ended up with (golf scoring system...) $YI = "SELECT (y1 + y2 + y3 + y4 + y5 + y6 + y7 + y8 + y9) AS yardsIn FROM tbl_courses WHERE courseID = $id"; $YO = "SELECT (y10 + y12 + y13 + y14 + y15 + y16 + y17 + y18) AS yardsOut FROM tbl_courses WHERE courseID = $id"; $yardsIn = mysql_query($YI, $golfscoring); $yardsOut = mysql_query($YO, $golfscoring); $Yin = mysql_fetch_assoc($yardsIn); $Yout = mysql_fetch_assoc($yardsOut); $yardsTotal = $Yin['yardsIn'] + $Yout['yardsOut']; <?php echo $Yin['yardsIn']; ?> <?php echo $Yout['yardsOut']; ?> <?php echo $yardsTotal; ?> thanks for the help people ! Quote Link to comment 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.