View Single Post
  #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
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01034 seconds
  • Memory Usage 1,769KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)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)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete