16.09.2016, 15:41
Quote:
I didn't, sorry.
This is working but can you explain the code.. I mean, how this work? Goddamn, MySQL is so hard to understand. >.< |
So DB::Fetch will load all the eligible rows. DB::Fetch also return a Cache id which can be useful when you want to perform more than one SELECT query i.e. more than one DB::Fetch at the same time.
So lets say we have 10 rows in table "Vehicles". According to this code:
pawn Код:
DB::Fetch("Vehicles");
So if you use fetch_row_id, it should return you "1" (primary keys starts as natural numbers but MySQL starts them as whole numbers).
So the first row is loaded and you can use the fetch_* functions to get its data. Now if you want to goto the next row, you can do so by fetch_next_row.
pawn Код:
DB::Fetch("Vehicles");
fetch_row_id(); // this is the 1st row
fetch_int("data");
fetch_next_row(); // skipped to next row
fetch_row_id(); // this will now return 2 i.e. 2nd row
fetch_int("data");
fetcher_close();
So as you done there, we'll similarly use loops (while - loop).
"Why we used do - while loop?" - Because if we directly do "while (fetch_next_row())", we will skip the first row every time.
pawn Код:
DB::Fetch("Vehicles", MAX_VEHICLES); // since we have a limit on vehicles
do
{
// fetch data here
}
while (fetch_next_row());
fetcher_close();