PDA

View Full Version : SQLite for loop only showing last DB entry?


Xenoyia
02/08/2012, 10:35 AM
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:

Misiur
02/08/2012, 10:44 AM
Well, your string will contain only information about last row because you use format on each iteration. I suggest something like:
//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

Xenoyia
02/08/2012, 10:58 AM
Well, your string will contain only information about last row because you use format on each iteration. I suggest something like:
//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. :(

Misiur
02/08/2012, 11:15 AM
After the loop add
printf("The full string: ", tmp);
Show what you get in console. If still only last entry - show me the query

Xenoyia
02/08/2012, 01:58 PM
After the loop add
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);

Misiur
02/08/2012, 02:09 PM
Damn, I'm retarded, forgot about %s
printf("The full string: %s", tmp);

Also: "SELECT * FROM `hats` DESC" is not fully valid sql query. I think you want something like
SELECT * FROM `hats` ORDER BY id DESC

Xenoyia
02/08/2012, 02:10 PM
Haha, sorry, I'm quite new to SQL in general.

Thanks, I'll try it out now.

Xenoyia
02/08/2012, 02:15 PM
Damn, I'm retarded, forgot about %s
printf("The full string: %s", tmp);

Also: "SELECT * FROM `hats` DESC" is not fully valid sql query. I think you want something like
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 :(

Misiur
02/08/2012, 02:21 PM
Are you using variable tmp or str in dialog? Str holds only last record, tmp has everything

Xenoyia
02/08/2012, 02:24 PM
Wow, thanks a lot for your help (+rep for you!) managed to get it working finally! :D

Now the only thing is the response.. blaah