Trying to combine two records (add) and display top10???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
j2ee
Forum Newbie
Posts: 5
Joined: Tue Jun 08, 2010 10:18 am

Trying to combine two records (add) and display top10???

Post by j2ee »

Hi, i'm working on a site that is currently having a voting competition. There are three rounds of voting, we are currently on the second. I've come up with this code so far and it works on the test site (so it seems) but not on the live site. It's supposed to count "votesSubmitted+bonusvotesSubmitted" and display the total, then list the top ten on the home page. What is happening is it isn't ordering them from most votes down. Here's the snippit: http://pastie.org/996396

Code: Select all

<div id="competition_table"> 
	<table> 
		<?php
		
		$i=1;
		$query_voters="SELECT id, nickname, votesSubmitted, bonusvotesSubmitted, status FROM ".DB_DATABASE.".accounts_2010 WHERE (accounts_2010.status='Voter' OR accounts_2010.status='Under Review' OR accounts_2010.status='Contestant') AND accounts_2010.nickname!='' ORDER BY (votesSubmitted+bonusvotesSubmitted) DESC, dateCreatedTimestamp ASC LIMIT 10";
		$result_voters=mysql_query($query_voters);
		while ($record_voters=mysql_fetch_object($result_voters))
		{
		?>
		<tr> 
			<td width="20"><?=$i?></td> 
			<td width="350"><?=$record_voters->nickname?></td> 
			<td width="20"><?=$record_voters->votesSubmitted+bonusvotesSubmitted?></td> 
		</tr> 
		<?php
			$i++;
		}
		?>
	</table>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trying to combine two records (add) and display top10???

Post by AbraCadaver »

Shouldn't this:

Code: Select all

<td width="20"><?=$record_voters->votesSubmitted+bonusvotesSubmitted?></td>
Be this:

Code: Select all

<td width="20"><?=$record_voters->votesSubmitted + $record_voters->bonusvotesSubmitted?></td>  
Also, I wouldn't use short tags <? as they aren't enabled on many servers and are not enabled by default anymore.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
j2ee
Forum Newbie
Posts: 5
Joined: Tue Jun 08, 2010 10:18 am

Re: Trying to combine two records (add) and display top10???

Post by j2ee »

Thanks Shawn, that did it. And thanks for the heads up on the short tags. I wasn't the original developer of the site, it just got dropped on my lap. Much appreciated!!!
Post Reply