sazuka Posted January 31, 2010 Share Posted January 31, 2010 Good eveing everyone , I got actually a simple problem but im really still new into PHP. Hope someone can find a solution to it.. I have a mysql table and I want to sum up all numbers inside the field Counts.. This is my table: -> example here the output would be 56.. ID Counts 1 5 2 5 3 10 4 36 Quote Link to comment https://forums.phpfreaks.com/topic/190448-counting-inside-rows/ Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 SELECT SUM(counts) FROM table Quote Link to comment https://forums.phpfreaks.com/topic/190448-counting-inside-rows/#findComment-1004616 Share on other sites More sharing options...
sazuka Posted January 31, 2010 Author Share Posted January 31, 2010 Thanks for the quick repls so this is how it would look like if im not wrong? Cause It still doesnt show :/ Table name: model and all rows of field wins <?php $show = 'SELECT SUM(wins) FROM models'; ?> <?php echo($show); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190448-counting-inside-rows/#findComment-1004647 Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 You have to fetch the data from MySQL mysql_connect, mysql_select_db mysql_query and finally mysql_fetch_assoc. Look into those functions or google a tutorial on how to pull data out of MySQL using PHP Quote Link to comment https://forums.phpfreaks.com/topic/190448-counting-inside-rows/#findComment-1004656 Share on other sites More sharing options...
sazuka Posted January 31, 2010 Author Share Posted January 31, 2010 Actually I have everything I believe Premiso I tried to make a new .php file and added this: No error and nothing shows up <?php session_start(); $con = mysql_connect("localhost", "dusername","passpass"); if(!$con){ echo('could not connect'.mysql_error()); } else{ mysql_select_db("Models",$con); ?> <?php $access = "Select SUM(Wins) From Models"; if(mysql_query($access)){ $resultaccess = mysql_query($access); echo('$resultaccess'); } ?> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/190448-counting-inside-rows/#findComment-1004661 Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 Two problems: if(mysql_query($access)){ $resultaccess = mysql_query($access); echo('$resultaccess'); } First, you are doing the query twice. Second, you are echoing a variable inside of Singlequotes, which takes $ literally. Revised version: if($resultaccess = mysql_query($access)){ $count = mysql_result($resultaccess, 0, 0); echo "Returned: " . $count; } As an offtopic note, you really do not need to go in and out of PHP like you do, stay in PHP while you are processing PHP. No need to go in and out. Quote Link to comment https://forums.phpfreaks.com/topic/190448-counting-inside-rows/#findComment-1004665 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.