schult70 Posted March 27, 2011 Share Posted March 27, 2011 How can I modify the following code to not display $hash_row['total'], but to display the sum of the counted "total" value + 1? Is there a way that I can assign that variable in the "select query" area (for instance, "COUNT(hr.hasher_id) + 1 as total1"), and then call $hash_row['total1] in the result table? I'm not sure if the syntax exists to add an integer value to a COUNT value and assign to a new variable... <?php include "modules/dbase_connection.php"; #create MySQL connection $sql_connection = sql_connect("blah","blah","blah","blah"); # select the Hashers and hashes by total number<br /> $hash_query = " SELECT ha.*, COUNT(hr.hasher_id) as total FROM hashers as ha, hash_records as hr WHERE hr.hasher_id = ha.hasher_id GROUP BY hr.hasher_id ORDER BY total DESC "; $hash_result = mysql_query($hash_query) or die(mysql_error()); $x = 1; while($hash_row = mysql_fetch_array($hash_result)) { #display the table header if($x == 1) { echo ' <br /> <table align="left"> <br /> <tbody> <tr><br /><td colspan="2"><strong>Potential On-Sec</strong></td><br /></tr>'; $x++; } echo '<tr><br /><td>' . $hash_row['hasher_name'] . '</td><br /><td>' . $hash_row['total'] . '</td><br /><td>- ' . $hash_row['real_name'] . '</td><br /></tr>'; } echo '</tbody></table></td><br />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/231898-how-to-add-integer-value-to-count-function/ Share on other sites More sharing options...
jcbones Posted March 28, 2011 Share Posted March 28, 2011 Yes, it will work. $hash_query = " SELECT ha.*, COUNT(hr.hasher_id) +1 as total FROM hashers as ha, hash_records as hr WHERE hr.hasher_id = ha.hasher_id GROUP BY hr.hasher_id ORDER BY total DESC "; Quote Link to comment https://forums.phpfreaks.com/topic/231898-how-to-add-integer-value-to-count-function/#findComment-1193086 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.