-6

我有一个 SQL 查询,我想将它插入到 PHP 文件中,就是这样

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

我希望它在浏览器中显示为

总数是:“SQL 的值”

你能帮我吗

4

2 回答 2

0

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);
于 2013-11-06T18:19:20.380 回答
0

你会想要使用 mysqli 库,文档在这里:http ://us1.php.net/mysqli_query

概述:

  • 创建数据库连接
  • 执行查询
  • 抓取结果集
于 2013-11-06T18:03:57.200 回答