Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2006, 02:01 AM
DigitalCrowd's Avatar
DigitalCrowd DigitalCrowd is offline
 
Join Date: Nov 2001
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How Do I: Recycle $db->fetch_array($qry) ?

Okay... I'm drawing a blank.

I do a query... example:

Code:
$qry=$db->query_read("SELECT field1,field2,field3 from vb_xyz WHERE field4='myvalue' and field8='Not_Processed'");

// SET FIELD8 TO PENDING TO STOP OVERLAPPING CRONS

while ($result=$db->fetch_array($qry)) {

    $db->query_write("UPDATE vb_xyz SET field8='Pending' WHERE field1='$result[field1]'");

}

// BEGIN PERFORMING ACTIONS, UPDATE DB FOR EACH FIELD ONCE COMPLETE

while ($result2=$db->fetch_array($qry)) {

    // action code here
    // this is what is not working, "$qry" seems to be "empty" or "finished"

}
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.
Reply With Quote
  #2  
Old 08-26-2006, 02:18 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 08-26-2006, 02:24 AM
DigitalCrowd's Avatar
DigitalCrowd DigitalCrowd is offline
 
Join Date: Nov 2001
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 08-26-2006, 02:34 AM
Code Monkey's Avatar
Code Monkey Code Monkey is offline
 
Join Date: May 2004
Posts: 1,080
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Or, better yet, you can use mysql_data_seek();

PHP Code:
$qry=$db->query_read("SELECT field1,field2,field3 from vb_xyz WHERE field4='myvalue' and field8='Not_Processed'");

// SET FIELD8 TO PENDING TO STOP OVERLAPPING CRONS

while ($result=$db->fetch_array($qry)) {

    
$db->query_write("UPDATE vb_xyz SET field8='Pending' WHERE field1='$result[field1]'");

}



mysql_data_seek($qry0);




// BEGIN PERFORMING ACTIONS, UPDATE DB FOR EACH FIELD ONCE COMPLETE

while ($result2=$db->fetch_array($qry)) {

    
// action code here
    // this is what is not working, "$qry" seems to be "empty" or "finished"


Reply With Quote
  #5  
Old 08-26-2006, 02:42 AM
DigitalCrowd's Avatar
DigitalCrowd DigitalCrowd is offline
 
Join Date: Nov 2001
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you. That worked perfectly. I think I need a vacation, I should have known that answer.
Reply With Quote
  #6  
Old 10-18-2007, 07:09 AM
mihai11 mihai11 is offline
 
Join Date: Dec 2005
Location: Sibiu - Romania
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Code Monkey View Post
Or, better yet, you can use mysql_data_seek();
I also had trouble with this and your answer helped. Thank you.
Reply With Quote
  #7  
Old 01-10-2008, 03:22 PM
mihai11 mihai11 is offline
 
Join Date: Dec 2005
Location: Sibiu - Romania
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looking thru the code, I found this function:

PHP Code:
function data_seek($queryresult$index
in the file class_code.php.

This seems to be doing what the OP requested using the VB coding standards.
Reply With Quote
  #8  
Old 01-13-2008, 10:04 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:33 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03978 seconds
  • Memory Usage 2,235KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete