stonelord Posted June 24, 2008 Share Posted June 24, 2008 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 https://forums.phpfreaks.com/topic/111589-showing-the-total-of-fields/ Share on other sites More sharing options...
hitman6003 Posted June 24, 2008 Share Posted June 24, 2008 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 https://forums.phpfreaks.com/topic/111589-showing-the-total-of-fields/#findComment-572782 Share on other sites More sharing options...
iversonm Posted June 24, 2008 Share Posted June 24, 2008 come on, i was going to answer that and you posted a reply before i could.. shoot haha but ya what he said Link to comment https://forums.phpfreaks.com/topic/111589-showing-the-total-of-fields/#findComment-572783 Share on other sites More sharing options...
stonelord Posted June 24, 2008 Author Share Posted June 24, 2008 Thank you very much, it works. But I am trying to understand the "0", what does it do? $test = mysql_result($result,0,'total_square_feet'); Link to comment https://forums.phpfreaks.com/topic/111589-showing-the-total-of-fields/#findComment-572800 Share on other sites More sharing options...
hitman6003 Posted June 24, 2008 Share Posted June 24, 2008 Selects the first row from the result set... http://www.php.net/mysql_result Link to comment https://forums.phpfreaks.com/topic/111589-showing-the-total-of-fields/#findComment-572802 Share on other sites More sharing options...
stonelord Posted June 24, 2008 Author Share Posted June 24, 2008 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 https://forums.phpfreaks.com/topic/111589-showing-the-total-of-fields/#findComment-572812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.