SQLite for loop only showing last DB entry? -
Xenoyia - 02.08.2012
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:
Re: SQLite for loop only showing last DB entry? -
Misiur - 02.08.2012
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
Re: SQLite for loop only showing last DB entry? -
Xenoyia - 02.08.2012
Quote:
Originally Posted by Misiur
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.
Re: SQLite for loop only showing last DB entry? -
Misiur - 02.08.2012
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
Re: SQLite for loop only showing last DB entry? -
Xenoyia - 02.08.2012
Quote:
Originally Posted by Misiur
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);
Re: SQLite for loop only showing last DB entry? -
Misiur - 02.08.2012
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
Re: SQLite for loop only showing last DB entry? -
Xenoyia - 02.08.2012
Haha, sorry, I'm quite new to SQL in general.
Thanks, I'll try it out now.
Re: SQLite for loop only showing last DB entry? -
Xenoyia - 02.08.2012
Quote:
Originally Posted by Misiur
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
Re: SQLite for loop only showing last DB entry? -
Misiur - 02.08.2012
Are you using variable tmp or str in dialog? Str holds only last record, tmp has everything
Re: SQLite for loop only showing last DB entry? -
Xenoyia - 02.08.2012
Wow, thanks a lot for your help (+rep for you!) managed to get it working finally!
Now the only thing is the response.. blaah