如何在PHP中显示查询? [关闭]

i have a SQL query and i want to insert it in a PHP file this is it

SELECT SUM( value )
FROM table name
WHERE field_id
IN ( 31, 33, 35, 37, 39, 41 ) 

i want it to appear in the browser as

the total is : "value of the SQL"

can you help me please

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);

You will want to use the mysqli library, the documentation is here: http://us1.php.net/mysqli_query

An overview:

  • Create a database connection
  • Execute the query
  • Grab the result set