Sorting and saving datagrid

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
mattrgs
Posts: 37
Joined: Tue May 28, 2013 1:41 pm

Sorting and saving datagrid

Post by mattrgs » Sun Apr 13, 2014 7:19 pm

Hi,
I have a datagrid which downloads the contents of a MySQL database table, this is downloaded with the entries in no particular order. The table has a name column and a score column. In the datagrid I want it to be sorted by the score (descending). This can be done easily, but here comes the problem. I then want to add a column which contains a position, just by going through a loop inserting numbers as I move down the table, however when I do this it becomes clear that when I am dealing with the DG data it hasn't been sorted, it is only the stuff in the datagrid which is sorted.
So I guess what I am asking is how can you sort a datagrid and the somehow save this sorting, so that when I manipulate the data the sorting is there?
Thanks,
Matthew

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 904
Joined: Fri Aug 15, 2008 7:15 am

Re: Sorting and saving datagrid

Post by bangkok » Sun Apr 13, 2014 7:37 pm

What's the name of your table ?

What's the name of your "score" column ?

Replace in your SQL query :

Code: Select all

select @rownum:=@rownum+1 ‘rank’, p.* from NAME_OF_YOUR_TABLE p, (SELECT @rownum:=0) r order by COLUMN_OF_SCORE desc
Last edited by bangkok on Sun Apr 13, 2014 8:09 pm, edited 1 time in total.

mattrgs
Posts: 37
Joined: Tue May 28, 2013 1:41 pm

Re: Sorting and saving datagrid

Post by mattrgs » Sun Apr 13, 2014 7:39 pm

Thanks, I wandered if this was possible
How would I include these in my code?
Thanks
Matthew

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 904
Joined: Fri Aug 15, 2008 7:15 am

Re: Sorting and saving datagrid

Post by bangkok » Sun Apr 13, 2014 8:12 pm

mattrgs wrote:Thanks, I wandered if this was possible
How would I include these in my code?
Thanks
Matthew
What's the name of your table ?

What's the name of your "score" column ?

Replace in your SQL query :

Code: Select all

select @rownum:=@rownum+1 ‘rank’, p.* from NAME_OF_YOUR_TABLE p, (SELECT @rownum:=0) r order by COLUMN_OF_SCORE desc

mattrgs
Posts: 37
Joined: Tue May 28, 2013 1:41 pm

Re: Sorting and saving datagrid

Post by mattrgs » Sun Apr 13, 2014 8:18 pm

I have entered it, and it returns this error code:
revdberr,You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘rank’, p.* from tTableName p, (SELECT @rownum:=0) r order by Score desc' at line 1

mattrgs
Posts: 37
Joined: Tue May 28, 2013 1:41 pm

Re: Sorting and saving datagrid

Post by mattrgs » Sun Apr 13, 2014 9:13 pm

In the end I did it slightly differently, as I realised that I wanted to do the ranking in a slightly different way that isn't possible with MySQL. For anyone's future interest here is my code with the table and column name emited:

Code: Select all

put "SELECT * FROM " & tTableName & " ORDER BY tColumnName DESC" into tSQL
    
    put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
Thanks for peoples help,
Matthew

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”