This is how to output row numbers with a SQL query:
SELECT @rownum:=@rownum+1 'num', col1, col2 FROM `dbname`, (SELECT @rownum:=0) r ORDER BY col1