Loading all data from the table -
thefatshizms - 05.03.2013
hello, i tried a query to load all the houses on OnGameModeInit with this query:
Код:
SELECT * FROM `house`
and this is the code to actually process the query and make the houses:
pawn Код:
public OnHousesLoaded()
{
new rows, fields;
cache_get_data(rows, fields, Gconnection);
if(rows) {
new owner[24], Intname[100], X[50], Y[50], Z[50], SQL[50], create;
cache_get_row(0, 1, owner);
cache_get_row(0, 3, Intname);
cache_get_row(0, 5, X);
cache_get_row(0, 6, Y);
cache_get_row(0, 7, Z);
cache_get_row(0, 0, SQL);
create = HouseCreate(owner, Intname, floatstr(X), floatstr(Y), floatstr(Z));
HouseInfo[create][SqlID] = strval(SQL);
print(" it's 'loaded'");
printf("%s %s %f %f %f %d", owner, Intname, floatstr(X), floatstr(Y), floatstr(Z), strval(SQL));
}
return 1;
}
It only loads the first row in the database.. I tried using a while loop but then it spammed loading the same thing.
Re : Loading all data from the table -
Shidony - 05.03.2013
You need to free the result at the end of your query.
Re: Loading all data from the table -
thefatshizms - 05.03.2013
R7 automatically free's the result. Also adding it in manually does no change.
Re: Loading all data from the table -
mamorunl - 05.03.2013
pawn Код:
public OnHousesLoaded()
{
new rows, fields;
cache_get_data(rows, fields, Gconnection);
if(rows) {
for(new i = 0; i < rows; i++) {
new owner[24], Intname[100], X[50], Y[50], Z[50], SQL[50], create;
cache_get_row(i, 1, owner);
cache_get_row(i, 3, Intname);
cache_get_row(i, 5, X);
cache_get_row(i, 6, Y);
cache_get_row(i, 7, Z);
cache_get_row(i, 0, SQL);
create = HouseCreate(owner, Intname, floatstr(X), floatstr(Y), floatstr(Z));
HouseInfo[create][SqlID] = strval(SQL);
print(" it's 'loaded'");
printf("%s %s %f %f %f %d", owner, Intname, floatstr(X), floatstr(Y), floatstr(Z), strval(SQL));
}
}
return 1;
}
rows gives you the number of rows back. So you can loop through them with a for loop, or a while, but you have to keep track of which rows you have done already.
Re: Loading all data from the table -
Djole1337 - 05.03.2013
Too late.
--
Re: Loading all data from the table -
thefatshizms - 05.03.2013
Quote:
Originally Posted by mamorunl
pawn Код:
public OnHousesLoaded() { new rows, fields; cache_get_data(rows, fields, Gconnection);
if(rows) { for(new i = 0; i < rows; i++) { new owner[24], Intname[100], X[50], Y[50], Z[50], SQL[50], create; cache_get_row(i, 1, owner); cache_get_row(i, 3, Intname); cache_get_row(i, 5, X); cache_get_row(i, 6, Y); cache_get_row(i, 7, Z); cache_get_row(i, 0, SQL);
create = HouseCreate(owner, Intname, floatstr(X), floatstr(Y), floatstr(Z)); HouseInfo[create][SqlID] = strval(SQL); print(" it's 'loaded'");
printf("%s %s %f %f %f %d", owner, Intname, floatstr(X), floatstr(Y), floatstr(Z), strval(SQL)); } } return 1; }
rows gives you the number of rows back. So you can loop through them with a for loop, or a while, but you have to keep track of which rows you have done already.
|
Thanks, it's exactly what I did basically but only with a while loop
![Smiley](images/smilies/smile.png)
+rap'ed
Quote:
Originally Posted by Mr_DjolE
Too late.
--
|
You should of kept your code, for your efforts I would have given you 2 rep.. I'll give you the rep anyways :P