退房SQL SUM()
聚合函數和IN
比較操作:
SELECT SUM(`number`) FROM `table` WHERE `id` IN (1,2,4);
UPDv1:
<?php
// hostname, username, password and database should be replaced with actual values.
$dbms = mysqli_connect('hostname', 'username', 'password', 'database');
if($dbms->connect_errno)die('MySQL connection error: ' . $dbms->connect_error);
// table should be replaced with actual table name.
$result = $dbms->query('SELECT SUM(`number`) as `amount` FROM `table` WHERE `id` IN (1,2,4)');
if($dbms->errno)die('MySQL error: ' . $dbms->error);
$row = $result->fetch_assoc();
echo $row['amount'];
?>
此外,檢查MySQLi驅動程序PHP是installed。
非常好,謝謝一堆! –