PDA

View Full Version : While there's a next row (in MySQL R33)


Neil.
15/10/2014, 02:54 AM
fixed.

Neil.
15/10/2014, 02:56 AM
double post. sorry

Chenko
15/10/2014, 02:57 AM
No, you need to use a loop as there is no function to go to the next row. A while loop works pretty well for this. Try something like this:


public OnHouseLoad()
{
new rows, fields, idx;
cache_get_data(rows, fields, mysql);

if(rows)
{
while(idx < rows)
{
HouseCount++;
houseInfo[HouseCount][slots] = cache_get_field_content_int(idx, "slots");
houseInfo[HouseCount][ownerid] = cache_get_field_content_int(idx, "ownerid");
houseInfo[HouseCount][price] = cache_get_field_content_int(idx, "price");

houseInfo[HouseCount][house_x] = cache_get_field_content_float(idx, "house_x");
houseInfo[HouseCount][house_y] = cache_get_field_content_float(idx, "house_y");
houseInfo[HouseCount][house_z] = cache_get_field_content_float(idx, "house_z");

if(ownerid != -1)
{
mysql_format(mysql, query, sizeof(query), "SELECT username FROM accounts WHERE id = %d", ownerid);
mysql_tquery(mysql, query, "GetNameFromID", "i", ownerid);
}
else
{
houseInfo[HouseCount][ownername] = GetNameFromID(
}
idx++;
}
}
return 1;
}

Neil.
15/10/2014, 03:00 AM
No, you need to use a loop as there is no function to go to the next row. A while loop works pretty well for this. Try something like this:


public OnHouseLoad()
{
new rows, fields, idx;
cache_get_data(rows, fields, mysql);

if(rows)
{
while(idx < rows)
{
HouseCount++;
houseInfo[HouseCount][slots] = cache_get_field_content_int(idx, "slots");
houseInfo[HouseCount][ownerid] = cache_get_field_content_int(idx, "ownerid");
houseInfo[HouseCount][price] = cache_get_field_content_int(idx, "price");

houseInfo[HouseCount][house_x] = cache_get_field_content_float(idx, "house_x");
houseInfo[HouseCount][house_y] = cache_get_field_content_float(idx, "house_y");
houseInfo[HouseCount][house_z] = cache_get_field_content_float(idx, "house_z");

if(ownerid != -1)
{
mysql_format(mysql, query, sizeof(query), "SELECT username FROM accounts WHERE id = %d", ownerid);
mysql_tquery(mysql, query, "GetNameFromID", "i", ownerid);
}
else
{
houseInfo[HouseCount][ownername] = GetNameFromID(
}
idx++;
}
}
return 1;
}


Cheers! :)