note 76050 added to function.mysql-data-seek

From: Date: Wed, 27 Jun 2007 20:26:54 +0000
Subject: note 76050 added to function.mysql-data-seek
Groups: php.notes 
Request: Send a blank email to php-notes+get-128036@lists.php.net to get a copy of this message
I needed to "peek" at the next record in order to see if fetching it would go too far. So I want to do a fetch, followed by seek(-1). I could find no function to move the internal row pointer relative to it's current position, or to retrieve it as a row number as required by mysql_data_seek(). This limits the function's usefulness to resetting the row to 0, unless you track the row number yourself. If you use a While loop to step through the results, you can increment a tracking index at the bottom of the loop. But be sure never to use Continue; which would bypass your index. And document this restriction for the person who needs to maintain your code. It's probably better to use a For loop, which makes the index explicit. In either case be sure to range check the index when you manipulate it. E.G. When I "peek" at the next record I must check for index>=count (end of data). Or if I decrement the index, make sure it does not go negative. Again, document why you are coding it this way, so the next programmer doesn't "correct" the inelegant code. ---- Server IP: 208.69.120.35 Probable Submitter: 24.131.35.146 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-data-seek.php Edit -- https://master.php.net/note/edit/76050 Del: integrated -- https://master.php.net/note/delete/76050/integrated Del: useless -- https://master.php.net/note/delete/76050/useless Del: bad code -- https://master.php.net/note/delete/76050/bad+code Del: spam -- https://master.php.net/note/delete/76050/spam Del: non-english -- https://master.php.net/note/delete/76050/non-english Del: in docs -- https://master.php.net/note/delete/76050/in+docs Del: other reasons-- https://master.php.net/note/delete/76050 Reject -- https://master.php.net/note/reject/76050 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128036) next »