RhysDamagnez Posted June 7, 2012 Share Posted June 7, 2012 Hi, sorry for poor code. I am new. I get the error Notice: Undefined index: COUNT(*) in C:\xampp\htdocs\money\index2.php on line 36 Line 36 being " echo '<td><strong>'.$data['COUNT(*)'].'</strong></td>'; " $db=@mysql_pconnect($host.($port==0?'':':'.((int)$port)),$username,$password); if(!$db || !@mysql_select_db($database,$db)){echo '<p>MySQL Error: '.mysql_error().'</p>'; exit();} $sql = mysql_query('SELECT user, COUNT(*) TotalCount FROM '.$table.' GROUP BY minecraft_user HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC'); //Define first rank. $rank = 1; ?> <center> <h1><u>iConomy Player Stats</u></h1> <table border="0" cellpadding="3" cellspacing="10" id="minimalist"> <tr> <td width="30"><strong>Username</strong></td> <td width="30"><strong>Voted Times</strong></td> <td width="30"><strong>Rank</strong></td> </tr> <?php while($data = mysql_fetch_assoc($sql)) { //Loops data and displays it in a table. echo '<tr>'; echo '<td><strong>'.$data['user'].'</strong></td>'; echo '<td><strong>'.$data['COUNT(*)'].'</strong></td>'; echo '<td><strong>'.$rank++.'</strong></td></tr>'; } ?> </table></center> Link to comment https://forums.phpfreaks.com/topic/263789-cant-get-mysql-count-to-show-in-php/ Share on other sites More sharing options...
.josh Posted June 7, 2012 Share Posted June 7, 2012 looks like from your sql query you meant to alias the COUNT(*) operation as TotalCount, but are missing the as: $sql = mysql_query('SELECT user, COUNT(*) TotalCount FROM '.$table.' GROUP BY minecraft_user HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC'); should be $sql = mysql_query('SELECT user, COUNT(*) as TotalCount FROM '.$table.' GROUP BY minecraft_user HAVING TotalCount > 1 ORDER BY TotalCount DESC'); and you should be using $data['TotalCount'] in your echo Link to comment https://forums.phpfreaks.com/topic/263789-cant-get-mysql-count-to-show-in-php/#findComment-1351789 Share on other sites More sharing options...
RhysDamagnez Posted June 7, 2012 Author Share Posted June 7, 2012 Thank you, so much Rookie mistake haha Link to comment https://forums.phpfreaks.com/topic/263789-cant-get-mysql-count-to-show-in-php/#findComment-1351791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.