Issue with Looping Through Data -
nmader - 03.07.2014
Alright, basically I'm trying to loop through data from a SQLite table and insert the unique information from each. Ex:
Sheriff Nathan Henderson
Undersheriff Connor Adams
Deputy Sheriff II DeAndre Smith
But all I can seem to get is:
Sheriff Nathan Henderson
Sheriff Nathan Henderson
Sheriff Nathan Henderson
Sheriff Nathan Henderson
Sheriff Nathan Henderson
Sheriff Nathan Henderson
Sheriff Nathan Henderson
Sheriff Nathan Henderson (And a bunch of other Sheriff Nathan Hendersons).
I've spent 5 hours trying to solve this issue with no success. Here's my code for it, there are no errors or warnings.
pawn Код:
case 5: //Employee Database
{
new DBResult:results;
new username[32], thirdstring[128], EmployeeDatabase[512];
new rank;
new test;
format(string, sizeof(string), "SELECT * FROM `Accounts` WHERE `Member` = '%d'", 1);
results = db_query(ServerDB, string);
if (db_num_rows(results) != 0)
{
printf("Returned %d rows", db_num_rows(results));
for(new rows=0;rows<db_num_rows(results);rows++)
{
format(username, 32, "%s", GetAccountString(results, "Username"));
rank = GetAccountInt(results, "Rank");
test++;
printf("Called %d times", test);
format(string, 128, FactionRank[1][rank]);
format(thirdstring, sizeof(thirdstring), "%s %s\n", string, username);
strcat(EmployeeDatabase, thirdstring);
}
ShowPlayerDialog(playerid, DIALOG_MDC_EMPLOYEES, DIALOG_STYLE_LIST, "Employee Database", EmployeeDatabase, "Select", "Back");
}
return 1;
}
I am using SQLite if that is needed to be known. I will +rep the person who helps me solve this as it's driving me nuts!
Re: Issue with Looping Through Data -
Vince - 03.07.2014
And what do GetAccountString and GetAccountInt do? If they poke into your database too, then you have a problem.
Re: Issue with Looping Through Data -
Konstantinos - 03.07.2014
With the example you gave, it's like there are more than 1 rows so use
db_next_row to move to the next row (place it after strcat function).
Re: Issue with Looping Through Data -
Stevo127 - 03.07.2014
You dont seen to get data from a specific row in the table, it could be continuously getting the first row.
Let me see GetAccountString() and GetAccountInt()
Re: Issue with Looping Through Data -
nmader - 03.07.2014
pawn Код:
stock GetAccountInt(DBResult:result, field[])
{
new str[16];
db_get_field_assoc(result, field, str, sizeof(str));
//mysql_get_row(
return strval(str);
}
stock Float:GetAccountFloat(DBResult:result, field[])
{
new str[16];
db_get_field_assoc(result, field, str, sizeof(str));
return floatstr(str);
}
stock GetAccountString(DBResult:result, field[])
{
new str[256];
db_get_field_assoc(result, field, str, sizeof(str));
return str;
}
I'm going to check out your method now Konstantinos.
Re: Issue with Looping Through Data -
Stevo127 - 03.07.2014
Quote:
Originally Posted by Konstantinos
With the example you gave, it's like there are more than 1 rows so use db_next_row to move to the next row (place it after strcat function).
|
I'm unsure of the SQL you're using, but this sounds correct. You're not specifying a row each time. Try this ^
Re: Issue with Looping Through Data -
nmader - 03.07.2014
Quote:
Originally Posted by Stevo127
I'm unsure of the SQL you're using, but this sounds correct. You're not specifying a row each time. Try this ^
|
I just did and it worked. I definately gotta check out your SQLite tutorial, Kon. You have all been given reputation as you both had been useful and offered assistance with a more than fair level of integrity rather than for reputation. Thanks guys!