Sorting rows in database. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Sorting rows in database. (
/showthread.php?tid=398634)
Sorting rows in database. -
LetsOWN[PL] - 10.12.2012
Hello.
I have a little question.
I am trying to make log file in SQLite, so I can access it from not only SA-MP.
The problem is about sorting. I don't know how to display rows with biggest unix timestamp (recent added row).
To imagine you, what I am about, then take look at this table:
+---Table: Log
Date|xFrom|Text
123|abc|Yoyo
124|abb|Yoto
546|xxd|Hello
695|pwn|amx
+--------------|
If I will use this script:
pawn Код:
for(new i = 1; i < db_num_rows(db_Result); i++)
{
format(db_Query, 255, "Select xFrom from Log where rowid = 'i');
..
}
Will print:
And now, what do I have to do if I want to display it in this order?
Is there any way from pawn level to sort all data from table using ORDER BY expression?
Or do I have to do something else?
Greetz,
LetsOWN.
Re: Sorting rows in database. -
LarzI - 10.12.2012
Well, you could do it very easily by running the for loop in the opposite direction, I think:
pawn Код:
for(new i = db_num_rows(db_Result); i > 1; i--)
Re: Sorting rows in database. -
LetsOWN[PL] - 10.12.2012
Hey,
Yep, it might do the work
If yes, then I'd just have to rebuild my page-building script (i mean showing 8 results / page) and if everything's will be ok.. You can count for rep+ 
Thanks,
Greetz,
LetsOWN.
Re: Sorting rows in database. -
Sinner - 10.12.2012
You're making it far more complex then it needs to be, just sort the data in the query.
PHP код:
SELECT xFrom
FROM Log
WHERE rowid = 'i'
ORDER BY Date DESC;
use "ORDER BY Date ASC" to order the other way around.
Re: Sorting rows in database. -
LetsOWN[PL] - 10.12.2012
Quote:
Originally Posted by Sinner
You're making it far more complex then it needs to be, just sort the data in the query.
PHP код:
SELECT xFrom
FROM Log
WHERE rowid = 'i'
ORDER BY Date DESC;
use "ORDER BY Date ASC" to order the other way around.
|
I've tried this.
Not working 
Greetz,
LetsOWN.
Re: Sorting rows in database. -
Sinner - 10.12.2012
Quote:
Originally Posted by LetsOWN[PL]
I've tried this.
Not working 
Greetz,
LetsOWN.
|
Can you show me how you did it? Because I know for a fact that that query will work just fine.
EDIT: You're not supposed to fetch every single row one by one depending on the rowid. Fetch them all at once (without the loop), then loop through the resulting set.
Re: Sorting rows in database. -
LetsOWN[PL] - 10.12.2012
Quote:
Originally Posted by Sinner
EDIT: You're not supposed to fetch every single row one by one depending on the rowid. Fetch them all at once (without the loop), then loop through the resulting set.
|
I've done something silmilar. It's now working. However I am still working under separating results into pages (8 results per page), but I think I'll handle this on my own. Thank you any*wy 
Greetz,
LetsOWN