hello friends i want to add my table fields but i got a problem that when ever i add my field for example i enter two records one of ID 2313 having exam_Fee and transport_Fee and other having id of 2314 having same exam_fee and transport_fee.query for this which i gave is

$result = mysql_query ("SELECT SUM(exam_Fee+transport_Fee) FROM fee_info") or die (mysql_error());

      while($row = mysql_fetch_array($result))
{
		 
      $security=$row['SUM(exam_Fee+transport_Fee)'];
      echo "$security";	
}

Where "fee_info" is my table name.
what this code does it sum up exam_fee and transport_fee of both the ID's 2313 and 2314 which i don't want.i want to display only sum of exam_fee and transport_fee of only one id at time that when i give the id in search bar e.g 2313 it sum up the record of only it and in same manner when i gave the id 2314 it give me only the sum up of the id 2314 not others.

Thanks in Advance

try

SELECT id, SUM(exam_Fee+transport_Fee) FROM fee_info group by id

This will create a result set with two fields, the id and the sum of exam_Fee + transport_Fee.

If you only want the sum for one record use the where clause.

SELECT SUM(exam_Fee+transport_Fee) FROM fee_info where id = 2313

You could of course combine the two and also have the id in your result set

SELECT id,SUM(exam_Fee+transport_Fee) FROM fee_info where id = 2313 group by id

in select query you can take SUM() of values

commented: yet another useless post -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.