The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
|
#1
|
|||
|
|||
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 } |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|