I am attempting to sum the data from a specific column in a MySQL database and then echo it to the page. My code is as follows:
<?php
//Trackingboard Display
$mysqli = new mysqli('localhost', 'root', '', 'disolDemo');
$query = $mysqli->query("SELECT sum(totLocMiles) FROM odoboard WHERE waybill_ID = '3'") or die($msqli->error);
$sumTot = mysql_fetch_array($query);
echo $sumTot[0];
?>
What am I doing wrong?
you're mixing mysqli
with mysql
try this
$mysqli = new mysqli('localhost', 'root', '', 'disolDemo');
$query = $mysqli->query("SELECT sum(totLocMiles) as sum FROM odoboard WHERE waybill_ID = '3'") or die($msqli->error);
while($row = $query->fetch_assoc())
{
echo $row['sum'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.