Page 1 of 1

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

Posted: Tue Jun 08, 2010 10:21 am
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>

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

Posted: Tue Jun 08, 2010 10:31 am
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.

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

Posted: Tue Jun 08, 2010 10:41 am
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!!!