SQLite for loop only showing last DB entry?
#1

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:
Reply
#2

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
Reply
#3

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.
Reply
#4

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
Reply
#5

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);
Reply
#6

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
Reply
#7

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

Thanks, I'll try it out now.
Reply
#8

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
Reply
#9

Are you using variable tmp or str in dialog? Str holds only last record, tmp has everything
Reply
#10

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

Now the only thing is the response.. blaah
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)