1

i have this php code and keep on getting errors upon fixing each error. my code is as follows:

    <?php 
$id = $_GET['election'];

$result = mysql_query(
    sprintf("
        SELECT votes.party, COUNT(votes.vote_id)
        FROM votes
        WHERE election_id = %d
        GROUP BY election_id, votes.party
        ORDER BY COUNT(votes.vote_id) DESC",
        mysql_real_escape_string($id)
    )
);


$votes = false;
$winners = array();

while ( ($row = mysql_fetch_row($result) ) && ( ($votes==false) || ($row['vote_count']===$votes) ) ) {
  $winners[] = row['party'];
  $votes = $row['vote_count'];
}
echo '<hr><h3>'.'Results</h3><hr>'.'<h4>'.implode(' and ', $winners).' won with '.$votes.'</h4>';

?>

error is: Parse error: syntax error, unexpected '[' in /home/jahedhus/public_html/system2/electoral/countvotes.php on line 84

line 84 is:

$votes = $row['vote_count'];

any ideas guys? thanks in advance

Jahed Hussain
  • 113
  • 1
  • 1
  • 7
  • 1
    Check the PHP manual for `while()` function 'cause I think you have an error in your `while` loop... http://ca2.php.net/manual/en/control-structures.while.php – Frederick Marcoux Mar 24 '12 at 00:39
  • @FrederickMarcoux: I see nothing wrong with the `while` statement... Also when you post links to `php.net`, it's better just to do `php.net/function`, for example: http://php.net/while, because it's shorter and automatically redirects to a server local to the user who visits the link. Note also "by surrounding a group of statements **with curly braces**, or by *using the alternate syntax*:", if that's what you're objecting to. – mellamokb Mar 24 '12 at 00:41
  • @FrederickMarcoux You're allowed to have multiple expressions in the `while` condition. – jprofitt Mar 24 '12 at 00:41
  • @jprofitt Sorry, I didn't know. – Frederick Marcoux Mar 24 '12 at 00:44

1 Answers1

8

You're missing the $ on $winners[] = row['party']; It should be $winners[] = $row['party'];

jprofitt
  • 10,874
  • 4
  • 36
  • 46