PDA

View Full Version : How Do I: Recycle $db->fetch_array($qry) ?


DigitalCrowd
26 Aug 2006, 04:01
Okay... I'm drawing a blank.

I do a query... example:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



So, my hang up (and maybe someone can suggest a better way to do this) is with this second "while" loop. I want to keep overlapping cron runs (example, running every minute, but one cron launch script lasts longer than 1 minute) from duplicating efforts.

In the first loop, I update a given field to "Pending" status and in the second loop, I actually take action. I can't do this with one loop because I want to make sure that the Pending status is applied to the entire selected $qry before running a process, so no future spawned scripts duplicate what a previously spawned script is already attempting to complete.

I know in PHP you can take an array and set the counter back to 0. But, how do I do this with the mysql query and the while clause using fetch_array?

If you know of a better way to do what I want to do, Im open for suggestions.

Thanks!

PS - Above code is for example purposes only and not copied from my actual working code.

Paul M
26 Aug 2006, 04:18
In the first loop add a line to store each row in an array, then loop round that array for your second set of processing.

DigitalCrowd
26 Aug 2006, 04:24
Ah Ha! Why did I not think of that. Guess when your looking in one direction, sometimes other directions are blind.

I'd still be open to reseting that counter for the $qry if anyone knows how to do that. But, in the mean time... Paul's idea would solve my issue.

Code Monkey
26 Aug 2006, 04:34
Or, better yet, you can use mysql_data_seek();



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

DigitalCrowd
26 Aug 2006, 04:42
Thank you. That worked perfectly. I think I need a vacation, I should have known that answer. ;)

mihai11
18 Oct 2007, 09:09
Or, better yet, you can use mysql_data_seek();

I also had trouble with this and your answer helped. Thank you.

mihai11
10 Jan 2008, 17:22
Looking thru the code, I found this function:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



in the file class_code.php.

This seems to be doing what the OP requested using the VB coding standards.

Dismounted
13 Jan 2008, 12:04
Yes, you should use the $db->data_seek() alias for the function, as this keeps the database layer in there, which is needed when vBulletin includes different layers to cater for different database types.