Trying to convert db_fetch_object for Drupal 7
the syntax is incorrect, and the error is correct. If you need to track $i, you could do something like:

$i = 0;
foreach($result as $order){
  ...
  $i++;
}