Jump to content

Counting inside rows


sazuka

Recommended Posts

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

Link to comment
Share on other sites

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
  	}

  ?>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.