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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.