vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   multiple uses of fetch_array() (https://vborg.vbsupport.ru/showthread.php?t=189000)

AsscBB 08-24-2008 03:06 PM

multiple uses of fetch_array()
 
I'm trying to write some code where I scan through an array multiple times. The symptoms of my code lead me to belive that only the first call to fetch_array() is being used. Are there any limts on how many times you can run fetch_array against the same array?




PHP Code:

.
.
.
while(
$get_result=$db->fetch_array($get_results)) 
{
    
//do stuff 1
}

//do stuff 2

while($get_result=$db->fetch_array($get_results)) 
{
    
//do stuff 3
}

//do stuff 4

while($get_result=$db->fetch_array($get_results)) 
{
    
//do stuff 5
}
.
.



My when I activate my plug-in, it looks like "do stuff 3" and "do stuff 5" are being ignored.

If this is a limitation, any suggestions on an alternative?

Thanks!

RLShare 08-24-2008 03:26 PM

Each time fetch_array is called it moves an internal pointer to the next set of data. The way you have it set up, when the pointer reaches the last set of data the while loop ends. In order to do what you want you would need to use data_seek to move the internal pointer back to the first position after each while loop.

AsscBB 08-24-2008 05:05 PM

RLShare-

Works like a champ now! Thanks for the info!

Dismounted 08-25-2008 06:21 AM

You could store all the data into a variable in the first loop, then just loop this variable. I'm guessing it would be slightly faster - but I am not sure.


All times are GMT. The time now is 04:23 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.02714 seconds
  • Memory Usage 1,714KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete