Jump to content

unset($GLOBALS["attribsarr"][$i]) behaving unexpectedly in function...


Greywacke

Recommended Posts

sighs...despite the data all being there, with every possible loophole repaired - the sql query as follows and the recordset therafter were returned (but the unset command was not run, the data was still included in the mails sent) - the code below behaves unexpectedly. obviously something is wrong here.MySQL Query:

SELECT 	3_serviceattributes.text_AttributeDescription, 	3_serviceattributes.text_AttributeValue FROM 	9_supplierattributes LEFT JOIN (	3_serviceattributes) ON (	9_supplierattributes.bigint_AttributeID = 3_serviceattributes.bigint_AttributeID) WHERE 	3_serviceattributes.text_AttributeDescription LIKE "%Requirement%" AND 	3_serviceattributes.text_AttributeValue LIKE "%Pre-owned - White%" AND 	9_supplierattributes.bigint_ServiceID = 1 AND 	9_supplierattributes.bigint_RegionID = 28 AND 	9_supplierattributes.bigint_SupplierID = 24;

Resultset:

function dropattribs($status) {	switch ($status) {		case 2:			$sarray = "mailaddp";											// prospecting status 2			break;		case 4:			$sarray = "mailaddl";											// listed status 4			break;		default:			$sarray = "mailadds";											// active status 0	}	//echo mysql_real_escape_string("\r\ndropattribs(".$status.")");	for ($i = count($GLOBALS[$sarray]) - 1; $i > -1; $i--) {		$sdata = $GLOBALS[$sarray][$i];											// get supplier data		$arr = split(";;;",$sdata);												// split supplier array		$sid = $arr[6];													// get supplier id		//echo mysql_escape_string("\r\n\t".$arr[1]);		reset($GLOBALS["attribsarr"]);		foreach ($GLOBALS["attribsarr"] as $key => $value) {								// begin iterate form attributes			// select current attribute key and value for supplier that is not supported			$tsql = "SELECT 					3_serviceattributes.text_AttributeDescription, 					3_serviceattributes.text_AttributeValue 				FROM 					9_supplierattributes 				LEFT JOIN (					3_serviceattributes				) 				ON (					9_supplierattributes.bigint_AttributeID = 3_serviceattributes.bigint_AttributeID				) 				WHERE 					3_serviceattributes.text_AttributeDescription LIKE \"%".strtolower($key)."%\" AND 					3_serviceattributes.text_AttributeValue LIKE \"%".strtolower($value)."%\" AND 					9_supplierattributes.bigint_ServiceID = ".$GLOBALS["service"]." AND 					9_supplierattributes.bigint_RegionID = ".$GLOBALS["region"]." AND 					9_supplierattributes.bigint_SupplierID = ".$sid.";";			$result = mysql_query_errors($tsql, $conn , __FILE__ , __LINE__ , false);			//echo mysql_real_escape_string("\r\n\t\t\$GLOBALS[\"attribsarr\"][\"".$key."\"] = ".$value);			if ($result) {												// begin if mysql result				if ($row = mysql_fetch_array($result)) {								// begin while suppliers !attribs					unset($GLOBALS[$sarray][$i]);								// drop the supplier from the array					mysql_free_result($result);									// free mysql result after dropping					break;												// break out of attributes loop				}													// end while suppliers !attributes				mysql_free_result($result);										// free mysql result after looping			}														// end if mysql result		}															// end iterate form attributes	}																// end iterate suppliers array}

somebody please help! this function HAS to be fixed by monday. despite this, if a recordset is retrieved: the page level $sarray elements are not always being dropped. i have checked all four values in the compiled query, and did a test run with it - only to receive a recordset, all the evidence points to unset($GLOBALS[$sarray][$i]); not working in this instance. please tell me what you think - it is imperative that this function is working optimally.

Link to comment
Share on other sites

unset will never simply not work, notwithstanding the notes in the manual about it. If it's not doing what you're expecting, about all I can say is to print the values you're trying to unset to verify that you're telling it to do what you think you are.

Link to comment
Share on other sites

thanks... i'm currently resubmitting the form on the test site, i've added an echo for the environmental variable $GLOBALS[$sarray][$i], in the line before the unset is called.

Link to comment
Share on other sites

this issue has now been RESOLVED :)the problem was the remnant from the previous matching of these values - where the values retrieved from the form are converted inline with strtolower(), to lowercase:

3_serviceattributes.text_AttributeDescription LIKE \"%".strtolower($key)."%\" AND 3_serviceattributes.text_AttributeValue LIKE \"%".strtolower($value)."%\" AND

the SQL was made truly case insensitive, keeping in mind that the connection, database, table and text field collations are utf8_bin:

LOWER(3_serviceattributes.text_AttributeDescription) LIKE \"%".strtolower($key)."%\" AND LOWER(3_serviceattributes.text_AttributeValue) LIKE \"%".strtolower($value)."%\" AND

i truly can't believe i missed these lines! :)once again, thank you justsomeguy for giving me some clarity on what needed to be done. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...