Jump to content

adding col for total


desjardins2010

Recommended Posts

hi all I have this can someone help me I'm trying to get a total cost

 

<?php
//inventory report printable total value in stock
$connect = mysql_connect('*******') or die (mysql_error());
mysql_select_db('fminventory') or die (mysql_error());

$query = mysql_query("SELECT SUM(cost) FROM cars");
$query2 = mysql_fetch_array($query);

echo $query2;

?>

Link to comment
https://forums.phpfreaks.com/topic/223992-adding-col-for-total/
Share on other sites

You are trying to access the data wrong.

 

try echo $query2[0];

 

The mysql_fetch_array returns the data into an array.  The first element of the array is 0.

 

Also, query2 should probably be called something like result, to keep it less confusing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.