#!/bin/sh
echo 'content-type: text/html'
echo
echo '<body background=/background.gif>'
echo '<center>'

/usr/local/sql/bin/psql -d apples -q -t -F ' ' -c '
      select user, score from scores  order by score desc;' |
awk '
BEGIN { 
    printf("<table border=4>");
    printf("<tr><td align=right>%3s<TD>%-30s<td>%5s</tr>\n","Position", "Name","Points");
    }
{
    count = count+1;
    if ((count % 10) == 0) {
      printf("</table><table border=4>");
      printf("<tr><td align=right>%3s<TD>%-30s<td>%5s</tr>\n","Position", "Name","Points");
    }
    printf("<tr>");
    printf("<TD align=right>%3d<TD>%-30s<TD align=right>%3d\n", count,$1,$2);
}
'
echo '</table></center>'



#     select score
# 	from scores
# 	where user='$QUERY_STRING';
