SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 02/08/2012, 10:35 AM   #1
Xenoyia
Little Clucker
 
Join Date: Jul 2012
Posts: 26
Reputation: 0
Default SQLite for loop only showing last DB entry?

Can anyone tell me why this is only showing the last result?

Oops, sorry. Just realised I gave you the version I did after messing around:
__________________
[0.3e] xP// Playground [24/7] - Featuring Deathmatch, Roleplay, Freeroam, Parkour, Drifting, Racing, Stunting and more!
Please visit my forum, the xP// Gaming community!
http://www.xenoyia.com

Last edited by Xenoyia; 02/08/2012 at 03:20 PM.
Xenoyia is offline   Reply With Quote
Old 02/08/2012, 10:44 AM   #2
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: SQLite for loop only showing last DB entry?

Well, your string will contain only information about last row because you use format on each iteration. I suggest something like:
pawn Code:
//Above the loop
new tmp[499+1];
//Find
db_next_row(Result);
//Add before
strcat(tmp, string);
Now you have all strings in tmp variable
Misiur is offline   Reply With Quote
Old 02/08/2012, 10:58 AM   #3
Xenoyia
Little Clucker
 
Join Date: Jul 2012
Posts: 26
Reputation: 0
Default Re: SQLite for loop only showing last DB entry?

Quote:
Originally Posted by Misiur View Post
Well, your string will contain only information about last row because you use format on each iteration. I suggest something like:
pawn Code:
//Above the loop
new tmp[499+1];
//Find
db_next_row(Result);
//Add before
strcat(tmp, string);
Now you have all strings in tmp variable
That still only shows the last entry.
__________________
[0.3e] xP// Playground [24/7] - Featuring Deathmatch, Roleplay, Freeroam, Parkour, Drifting, Racing, Stunting and more!
Please visit my forum, the xP// Gaming community!
http://www.xenoyia.com
Xenoyia is offline   Reply With Quote
Old 02/08/2012, 11:15 AM   #4
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: SQLite for loop only showing last DB entry?

After the loop add
pawn Code:
printf("The full string: ", tmp);
Show what you get in console. If still only last entry - show me the query
Misiur is offline   Reply With Quote
Old 02/08/2012, 01:58 PM   #5
Xenoyia
Little Clucker
 
Join Date: Jul 2012
Posts: 26
Reputation: 0
Default Re: SQLite for loop only showing last DB entry?

Quote:
Originally Posted by Misiur View Post
After the loop add
pawn Code:
printf("The full string: ", tmp);
Show what you get in console. If still only last entry - show me the query
Just shows "The full string: "

format(Query, sizeof(Query), "SELECT * FROM `hats` DESC");
Result = db_query(dtbase, Query);
__________________
[0.3e] xP// Playground [24/7] - Featuring Deathmatch, Roleplay, Freeroam, Parkour, Drifting, Racing, Stunting and more!
Please visit my forum, the xP// Gaming community!
http://www.xenoyia.com
Xenoyia is offline   Reply With Quote
Old 02/08/2012, 02:09 PM   #6
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: SQLite for loop only showing last DB entry?

Damn, I'm retarded, forgot about %s
pawn Code:
printf("The full string: %s", tmp);

Also: "SELECT * FROM `hats` DESC" is not fully valid sql query. I think you want something like
Code:
SELECT * FROM `hats` ORDER BY id DESC
Misiur is offline   Reply With Quote
Old 02/08/2012, 02:10 PM   #7
Xenoyia
Little Clucker
 
Join Date: Jul 2012
Posts: 26
Reputation: 0
Default Re: SQLite for loop only showing last DB entry?

Haha, sorry, I'm quite new to SQL in general.

Thanks, I'll try it out now.
__________________
[0.3e] xP// Playground [24/7] - Featuring Deathmatch, Roleplay, Freeroam, Parkour, Drifting, Racing, Stunting and more!
Please visit my forum, the xP// Gaming community!
http://www.xenoyia.com
Xenoyia is offline   Reply With Quote
Old 02/08/2012, 02:15 PM   #8
Xenoyia
Little Clucker
 
Join Date: Jul 2012
Posts: 26
Reputation: 0
Default Re: SQLite for loop only showing last DB entry?

Quote:
Originally Posted by Misiur View Post
Damn, I'm retarded, forgot about %s
pawn Code:
printf("The full string: %s", tmp);

Also: "SELECT * FROM `hats` DESC" is not fully valid sql query. I think you want something like
Code:
SELECT * FROM `hats` ORDER BY id DESC
Well, the print shows everything I want it to show, all rows in the database etc. But it still only shows one in the dialog
__________________
[0.3e] xP// Playground [24/7] - Featuring Deathmatch, Roleplay, Freeroam, Parkour, Drifting, Racing, Stunting and more!
Please visit my forum, the xP// Gaming community!
http://www.xenoyia.com
Xenoyia is offline   Reply With Quote
Old 02/08/2012, 02:21 PM   #9
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: SQLite for loop only showing last DB entry?

Are you using variable tmp or str in dialog? Str holds only last record, tmp has everything
Misiur is offline   Reply With Quote
Old 02/08/2012, 02:24 PM   #10
Xenoyia
Little Clucker
 
Join Date: Jul 2012
Posts: 26
Reputation: 0
Default Re: SQLite for loop only showing last DB entry?

Wow, thanks a lot for your help (+rep for you!) managed to get it working finally!

Now the only thing is the response.. blaah
__________________
[0.3e] xP// Playground [24/7] - Featuring Deathmatch, Roleplay, Freeroam, Parkour, Drifting, Racing, Stunting and more!
Please visit my forum, the xP// Gaming community!
http://www.xenoyia.com
Xenoyia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
for( ) loop vs while( ) loop | While( ) loop is 143x faster? zgintasz Scripting Help 17 03/07/2012 12:57 PM
Loop with SQLite Cowboy Scripting Help 4 20/10/2011 10:34 AM
Entry Key Skidmarks Help Archive 1 27/05/2011 03:17 PM
no entry fff Help Archive 3 17/03/2009 08:07 PM


All times are GMT. The time now is 05:04 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.