0
figure 1. sum all value of money id date name money //sample items only 1 March 5 2014 matt 50 //records to add 2 March 5 2014 john 10 //records to add 3 March 2 2014 matt 50 //records to add figure 2. sum all value of money when search matt id date name money //sample items only 1 March 5 2014 matt 50 //records to add 2 March 5 2014 john 10 3 March 2 2014 matt 50 //records to add 

Hi guys can you help me i dont know the code how to Add the rows value in my sql database.(see sample above)

i have this code which will count how many records i have

<input type="text" name="namesearch" size="5" tabindex="1" /> <input type="submit" name='click' value='Search' /> if(isset($_POST['click'])){ $name= $_POST['namesearch']; $query = "SELECT COUNT(*) AS total FROM table WHERE name='$name'"; $result = mysql_query($query); $values = mysql_fetch_assoc($result); $num_item= $values['total']; echo "Number of Records Found # ".$num_item; 
2
  • 1
    what you tried in your query? Commented Mar 5, 2014 at 6:47
  • mysql_num_rows($result) Commented Mar 5, 2014 at 6:51

3 Answers 3

3

use this as query

$query = "SELECT COUNT(*) AS total, SUM(money) AS total_money FROM table WHERE name='$name'"; 

use this to view the result

$num_item = $values['total']; $total_value = $values['total_money']; echo "Number of Records Found # ".$num_item; echo "Total Money ".$total_value 
Sign up to request clarification or add additional context in comments.

Comments

0

Since my MySQL server is missing after an OS upgrade, don't trust the syntax (lol). Try this:

SELECT COUNT(*), SUM(`money`) AS `total_money` FROM `my_table` GROUP BY `name`; 

This should(?) give you the count of rows for each name and it's sum of total money.

Comments

0

Use MySQL SUM Function

SELECT SUM(money) AS total FROM table WHERE name='$name' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.