lindisfarne Posted October 13, 2016 Share Posted October 13, 2016 In the code below I can get the total of the column into the field in a table,but how would I go about this if I wanted to get the total into a text box(html).I tried placing the $total variable into the value attribute of the text box but this didn't work.Any suggestions much appreciated:) $total = 0; // initialise totalwhile($record = mysql_fetch_array($myData)){echo "<tr>";echo "<td>" . $record['id'] . "</td>";echo "<td>" . $record['author'] . "</td>";echo "<td>" . $record['title'] . "</td>";echo "<td>" . $record['publisher'] . "</td>";echo "<td>" . $record['year'] . "</td>";echo "<td>" . $record['genre'] . "</td>";echo "<td>" . $record['sold'] . "</td>";echo "<tr />";$total += $record['sold']; // accumulate total}echo "<tr><td colspan='6'>Total:</td><td>$total</td></tr>"; // output totalecho "</table>"; Kind regards Lind Quote Link to comment https://forums.phpfreaks.com/topic/302324-getting-sum-of-a-column-from-a-table-into-a-textbox/ Share on other sites More sharing options...
Barand Posted October 13, 2016 Share Posted October 13, 2016 (edited) Are you referring to an input box of type "text" or a textarea element? If the former then using the value attribute should work. echo "<input type='text' name='total' value='$total' />"; If you mean the latter then there is no value attribute. The text content goes between the open and close tags echo "<textarea rows='2' cols='20' name='total'>$total</textarea>"; Basic HTML. And please use code tags, or the "<>" button in the toolbar. Edited October 13, 2016 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/302324-getting-sum-of-a-column-from-a-table-into-a-textbox/#findComment-1538241 Share on other sites More sharing options...
cyberRobot Posted October 13, 2016 Share Posted October 13, 2016 Side note: In case you are not aware, the mysql_* functions have been removed from the latest version of PHP. You will want to switch to PDO or MySQLi in the near future. More information can be found here: http://php.net/manual/en/mysqlinfo.api.choosing.php Quote Link to comment https://forums.phpfreaks.com/topic/302324-getting-sum-of-a-column-from-a-table-into-a-textbox/#findComment-1538244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.