如何使用php从数据库中添加结果

Hi guys i am a newbie in php. I have a code in php I want to add data in mysql like this

Table sample

id   value1 value2  P_id
1    100     200     10
2    200     50      10

Here is my code

$query = mysql_query("SELECT * from sample P_id = '10'");
while($row = mysql_num_rows($query)){
    // Here is the condition I don't now what will be the code if I want to add
}

like this I want a result for value1 will be 300 and value2 250 when I display could you please help me with this thanks a lot

You're missing the where in your select:

mysql_query("SELECT * from sample WHERE P_id = '10'");

This is the right query you need run up against..

   mysql_query("SELECT SUM(value1) as Value1, SUM(value2) as Value2 FROM sample WHERE P_id = '10'");
   while($row = mysql_num_rows($query)){
    echo "Value 1:$row['Value1'];  Value 2:$row['Value2']";
   }

OUTPUT:

Value1 Value2
300    250

This is not a valid SQL statement:

SELECT * from sample P_id = '10'