Maybe you want something like this (example with mysql):
    $conection = mysql_connect ("localhost","root","")
        or die("Can't connect to the database");
    mysql_select_db("database name") or die ("Can't connect to the database");
    $sel="SELECT SUM( value )
        FROM table_name
        WHERE field_id
        IN ( 31, 33, 35, 37, 39, 41 )";
    $query = mysql_query($select,$conexion) or die ("Bad.");
    $row=mysql_fetch_array($query);
Now, $row is an array whith the first row resultant. So $row[0] is your result.
To catch the next one just repeat:
&row=mysql_fetch_array($query);
solved How to show the query inside PHP? [closed]