1

Topic: DB lookup question

If one has a db query/lookup which will return multiple rows, would the following just return the required item from the first row of the result all or rows?

list($lastpost) = $db->fetch_row($result);

Result is a lookup which is ordered by last post, so the first row has the last post info I require, but I'm not quite sure if the above will work as I think/expect. big_smile Plus, running that command would still leave all the info in result as is, to be used in a while loop later on?


Thanks again,

Matt

Re: DB lookup question

It'll get the current row and advance the internal resultset pointer by one. You can reset that pointer so you can use the thing again later on.

3

Re: DB lookup question

Cheers. smile Just one last question. How does one reset the pointer?


Thanks again,

Matt

Re: DB lookup question

http://be.php.net/manual/en/function.my … a-seek.php

5

Re: DB lookup question

Just making sure I'm not missing the gist on that link. big_smile So effectively, calling:

$result->data_seek(0);

would reset the pointer back to zero so that a later fetch_assoc in a while loop would start from the beginning again?


Thanks again,

Matt

Re: DB lookup question

Whoops, I gave you the MySQLi one big_smile

For regular MySQL it would be:

mysql_data_seek($result, 0);

7

Re: DB lookup question

big_smile big_smile

Thanks again. smile Just cross referenced that one to the pgsql variant:

pg_result_seek($result, 0);

and it works an absolute treat. smile