BlueG simple MySQL load question. -
Kaaajmak - 04.01.2013
Alright. So, what I need resolved is how to read through a query result, that has more than one row.
The code:
PHP код:
for(new i = 0; i < mysql_num_rows(); i++)
{
new row[128];
new field[5][128];
mysql_fetch_row_format(row, "|");
explode(row, field, "|");
CarStats[playerid][Unid][i] = strval(field[0]);
CarStats[playerid][Carid][i] = strval(field[1]);
CarStats[playerid][Ownerid][i] = strval(field[2]);
CarStats[playerid][Color1][i] = strval(field[3]);
CarStats[playerid][Color2][i] = strval(field[4]);
mysql_retrieve_row(); //Described to be the same as mysql_next_row();
}
I tried that, but it doesn't seem to work.
The MySQL query is:
PHP код:
new str[128];
format(str, sizeof(str), "SELECT * FROM Cars WHERE Ownerid = '%d'", UserStats[playerid][Uniqueid]);
mysql_query(str);
mysql_store_result();
I need this resolved ASAP. Thank you
EDIT: IT'S NOT THE VERSION WITH CASHING! I know how to do it in that version, but I don't know how to here.
Re: BlueG simple MySQL load question. -
[HiC]TheKiller - 04.01.2013
pawn Код:
new str[128];
format(str, sizeof(str), "SELECT * FROM Cars WHERE Ownerid = '%d'", UserStats[playerid][Uniqueid]);
mysql_query(str);
mysql_store_result();
while(mysql_retrieve_row())
{
new row[128];
new field[5][128];
mysql_fetch_row_format(row, "|");
print(row); //See what this prints and if it even pritns
explode(row, field, "|"); //sscanf is probably better than explode.
CarStats[playerid][Unid][i] = strval(field[0]);
CarStats[playerid][Carid][i] = strval(field[1]);
CarStats[playerid][Ownerid][i] = strval(field[2]);
CarStats[playerid][Color1][i] = strval(field[3]);
CarStats[playerid][Color2][i] = strval(field[4]);
}
mysql_free_result();
Re: BlueG simple MySQL load question. -
Vince - 04.01.2013
That will only load half the results because both mysql_retrieve_row and mysql_fetch_row_format advance the row pointer. So you'll end up with one row loaded, one row skipped, one row loaded, one row skipped ... Fetch the row in the while clause. Delete mysql_retrieve_row.
Re: BlueG simple MySQL load question. -
Kaaajmak - 04.01.2013
This.. Works.. Up to a point..
The problem is, it loads from the second car, not the first (skips the first one) and all after that are read as null.
Basically it looks something like this(the print(row)):
2|420|4|23|3
(null)
[CAR SYSTEM] Loaded 2 cars for Sgt_Kajmak ( ID 0 )
Re: BlueG simple MySQL load question. -
Kaaajmak - 04.01.2013
EDIT: @Vince, Thank you so much, it works now. I wasn't aware it advanced the pointer.
It was too late to update to R7 so I decided to bother with this..
Thank you to you both.