I am fetching an array of data from SQL, and then concatenating them as strings for display. The function looks like this:
function FetchTopStats( Conn, iLimit )
local sToReturn = "\tS.No. \t UserName \t Score\n\t"
SQLQuery = assert( Conn:execute( string.format( [[SELECT username, totalcount FROM chatstat ORDER BY totalcount DESC LIMIT %d]], iLimit ) ) )
DataArray = SQLQuery:fetch ({}, "a")
i = 1
while DataArray do
sToReturn = sToReturn..tostring( i ).."\t"..DataArray.username.." \t "..DataArray.totalcount.."\n\t"
DataArray = SQLQuery:fetch ({}, "a")
i = i + 1
end
return sToReturn
end
This gives me an output like:
S.No. UserName Score
1 aim 6641
2 time 5021
3 Shepard 4977
and so on. I am thinking of using a string.format
function, to have a display as follows:
S.No. UserName Score
1 aim 6641
2 time 5021
3 Shepard 4977
But, I am totally out of ideas on how to have this. The only option coming to my mind is checking string length of username, and then applying \t
accordingly. That, I want to use at the very last.