我有一个 SQL 查询,我想将它插入到 PHP 文件中,就是这样
SELECT SUM( value )
FROM table name
WHERE field_id
IN ( 31, 33, 35, 37, 39, 41 )
我希望它在浏览器中显示为
总数是:“SQL 的值”
你能帮我吗
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);