'EasyData' (MySQL) Problem
#6

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
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. >.<
Well DB::Fetch is an alternative (easy one) to SELECT queries and also you can perform SORT functions as well in it.

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");
All the 10 rows will be loaded.

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();
But its not good to individually load all rows. In this case we only have 10 rows but if you have upto something like MAX_VEHICLES, you'll be done with programming !

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();
Also, fetch_next_row returns a boolean, if its true that means next row is existing in the table and has been loaded, false means NO.
Reply


Messages In This Thread
'EasyData' (MySQL) Problem - by Dayrion - 15.09.2016, 21:01
Re: 'EasyData' (MySQL) Problem - by Dayrion - 16.09.2016, 14:10
Re: 'EasyData' (MySQL) Problem - by Konstantinos - 16.09.2016, 14:17
Re: 'EasyData' (MySQL) Problem - by Gammix - 16.09.2016, 14:29
Re: 'EasyData' (MySQL) Problem - by Dayrion - 16.09.2016, 15:16
Re: 'EasyData' (MySQL) Problem - by Gammix - 16.09.2016, 15:41
Re: 'EasyData' (MySQL) Problem - by Dayrion - 16.09.2016, 16:25
Re: 'EasyData' (MySQL) Problem - by Gammix - 16.09.2016, 21:32
Re: 'EasyData' (MySQL) Problem - by Dayrion - 17.09.2016, 09:37

Forum Jump:


Users browsing this thread: 3 Guest(s)