Jump to content

Showing the total of fields


stonelord

Recommended Posts

I have a field on my table the tracks square footage. At the bottom of the table on my page I'd like to show the total square footage entered, but my code is not working. Here is my code and this is the error I get; Call to undefined function mysql_query_add() in /home/ci/public_html/remakes/remakes_index.php

 

<?php
$result = mysql_query_add('SELECT SquareFeet FROM sqtable');

if (!$result) {
  exit('<p>Error performing query: ' .mysql_error().
  '</p>');
  }
  
echo "<table border='1' bordercolor='#666633' cellpadding='3' cellspacing='0'>";
echo '<tr> <th bgcolor="#999966">Total Square Footage</th></tr>';

while ($row = mysql_fetch_array($result)) {
echo '<tr><td>';
echo $row['SquareFeet'];
echo '</td></tr>';
}

?>

Any suggestions?

Link to comment
Share on other sites

mysql_query_add is not a function in php.

 

I think you want something like this:

 

SELECT SUM(SquareFeet) AS total_square_feet FROM sqtable

 

Which you would use like so:

 

$result = mysql_query($query);

echo 'Total Square Footage: ' . mysql_result($result, 0, 'total_square_feet');

Link to comment
Share on other sites

Thanks again!

I just thought of something. (I haven't tried this yet) but is there a way to show this same total (square footage) on my main page? (just the total to trasnfer and also update itself on the main page?). Would you have to rewrite the holw query again on the main page?

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.