desjardins2010 Posted January 10, 2011 Share Posted January 10, 2011 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 More sharing options...
guyfromfl Posted January 10, 2011 Share Posted January 10, 2011 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. Link to comment https://forums.phpfreaks.com/topic/223992-adding-col-for-total/#findComment-1157512 Share on other sites More sharing options...
desjardins2010 Posted January 10, 2011 Author Share Posted January 10, 2011 thanks that worked... Link to comment https://forums.phpfreaks.com/topic/223992-adding-col-for-total/#findComment-1157566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.