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 06-24-2008, 02:25 PM
AsscBB AsscBB is offline
 
Join Date: Dec 2007
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Problem with passing query results to a function

Please check my process and help me understand where I'm going wrong.

I'm taking the results from a query and passing them to a function where I'm deconstructing the info in a while loop and running conditionals. Is this the right way to do this? I have comments in the code for what I think the code is doing (or at least what I want it to do) so I can also put this in my cheat sheet for future use. The code is not currently providing the output I desire. The problem I'm seeing is that I don't think the while loop is scanning through the array like I assume it is. Am I going crazy???


Thanks!




Code:
function check_fields($my_values) //this is my custom function with my array as a pass parameter.  The name does not need to be the same but I'm leaving it the same for sake of simplicity
{
	while ($my_value=$db->fetch_array($my_values)  //this while loop goes through the array entry by entry.  If there were 10 instances of field5 = $some_var from earlier, this code would be executed 10 times - once for each entry
	{
		if($my_value['field1'] == $field1_var)  //This goes to the array and runs a conditional against "field1".  The name of the fields here corresponds with the name of the fields in the origional table
		{
			//Do something for this if true
		}
		if($my_value['field2'] == $field2_var)  //Same as before but for a different table
		{
			//Do something for this if true
		}
		if($my_value['field3'] == $field3_var)
		{
			//Do something for this if true
		}
		if($my_value['field4'] == $field4_var)
		{
			//Do something for this if true
		}
		if($my_conditional == true)
		{
			return false; //if $my_conditional = true then retun a value of "false" to the calling function
		}
		else
		{
			return true; //if $my_conditional = false then retun a value of "true" to the calling function
		}
 	}
}


$my_values=$db->query("SELECT 'field1','field2','field3','field4' FROM " . TABLE_PREFIX . "demo_table WHERE field5=".$some_var);
	//$my_values is now an array that is 4 fields wide and has as many rows as the number of occurances of field5 = $some_var
if (check_fields($my_values))  //This sends the $my_values array to a custom function and expects a true or false as a return value
{
	//Do something
}
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 02:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03349 seconds
  • Memory Usage 2,198KB
  • 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)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (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_threadedmode.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_threaded
  • showthread_threaded_construct_link
  • 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