Jump to content

why would unset not be dropping elements from a page level array in a function?


Greywacke
 Share

Recommended Posts

hi...in the mysql database, these attribute keys and values are stored as utf8_bin - but the data was entered as ascii - is it possible that a value cannot be matched due to the conversion of collation? there is a dash in some values and these are where it messes up. i notice that there are about 5 dash characters in utf8 - two lengths which can be confused. i am at a total loss here, i have absolutely no concrete clue as to why this would be happening.i believe the problem is with the dropattribs function, which drops suppliers retrieved into an array from the array - if an attribute unsupported by the supplier is found in the consumer data from the form.in the following function it iterates the attributes from the consumer, and depending on the supplier status to be checked - gets which supplier array it should iterate. it then iterates the consumer attributes, selecting the unsupported attributes for the supplier, and checking each of them for each iteration of consumer attributes. if a consumer has two or more unsupported attributes, then the flag was marked on dropping the supplier at the first iteration - and no more drops will occur for that supplier. is there perhaps a way that this function can be optimised? i am also looking for possible solutions as to why some suppliers are not dropped by non-attributes. after a few weeks of searching the net, i can't seem to come upon a logical explanation of why this is happening...

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	}	for ($i = 0; $i < count($GLOBALS[$sarray]); $i++) {		$sdata = $GLOBALS[$sarray][$i];												// get supplier data		$arr = split(";;;",$sdata);													// split supplier array		$sid = $arr[6];														// get supplier id		foreach ($GLOBALS["attribsarr"] as $key => $value) {									// begin iterate form attributes			$unset = false;													// reset the unset flag for this iteration			// select current attribute key and bound values for supplier that are not supported			$tsql = "SELECT 3_serviceattributes.text_AttributeDescription, 3_serviceattributes.text_AttributeValue FROM 9_supplierattributes JOIN (3_serviceattributes) ON (9_supplierattributes.bigint_AttributeID = 3_serviceattributes.bigint_AttributeID) WHERE 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);			if ($result) {													// begin if mysql result				while ($row = mysql_fetch_array($result)) {								// begin while suppliers !attribs					// begin if db key and value in attrib key and value					if (!$unset && stristr(trim($key),strval($row["text_AttributeDescription"])) != false && 	// if !unset & key & value in supplier !attribute						stristr(trim($value),strval($row["text_AttributeValue"])) != false) {			// "							unset($GLOBALS[$sarray][$i]);							// drop the supplier from the array							$unset = true;									// set unset flag to true					}													// end if key & value in supplier !attribute				}														// 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}

the various supplier arrays are populated by the following function:

function getsuppliers($sid,$status) {	switch ($status) {		case 2:			$sarray = "mailaddp";			break;		case 4:			$sarray = "mailaddl";			break;		default:			$sarray = "mailadds";	}	$GLOBALS[$sarray] = array();	// try check for all attributeid's within loop for supplier	// make possible values == 0 (active), 2 (prospecting) or 4 (listed)	$sql1 = "SELECT 			5_suppliers.text_ContactFirstName, 			5_suppliers.text_ContactSurname, 			5_suppliers.text_SupplierName, 			5_suppliers.`text_ContactE-mail`, 			5_suppliers.bigint_CurrentBalance, 			5_suppliers.bigint_ContactTel, 			5_suppliers.text_SupplierAddress, 			5_suppliers.bigint_SupplierID, 			5_suppliers.text_GoogleMapsURL, 			5_suppliers.text_VTigerData, 			5_suppliers.tinyint_VariablePricingEnabled, 			5_suppliers.smallint_SupplierStatus, 			4_servicesuppliers.timestamp_LastLeadSentDate 		FROM 			5_suppliers 		LEFT JOIN (			4_servicesuppliers		) 		ON (			4_servicesuppliers.bigint_SupplierID = 5_suppliers.bigint_SupplierID		) 		WHERE 			CURRENT_TIMESTAMP >= 5_suppliers.timestamp_DateStart AND 			CURRENT_TIMESTAMP <= 5_suppliers.timestamp_DateEnd AND 			5_suppliers.smallint_SupplierStatus = ".$status." AND 			4_servicesuppliers.bigint_ServiceID = ".$sid." AND 			4_servicesuppliers.bigint_RegionID = ".$GLOBALS["region"]." 		ORDER BY 			4_servicesuppliers.timestamp_LastLeadSentDate ASC;";	$result1 = mysql_query_errors($sql1, $conn , __FILE__ , __LINE__ , true);	if ($result1) {		while ($row1 = mysql_fetch_array($result1)) {			$servicecost = costbycategory($GLOBALS["service"],$GLOBALS["attribsarr"],$row1["tinyint_VariablePricingEnabled"]);			if (!str_in_array(";;;".$row1["text_SupplierName"].";;;",$GLOBALS[$sarray]) && (($status==2||$status==4)?true:($row1["bigint_CurrentBalance"] >= $servicecost))) {				array_push($GLOBALS[$sarray], xmlentities($row1["text_ContactFirstName"]." ".$row1["text_ContactSurname"]).";;;".$row1["text_SupplierName"].";;;".$row1["text_ContactE-mail"].";;;".$row1["bigint_CurrentBalance"].";;;".$row1["bigint_ContactTel"].";;;".$row1["text_SupplierAddress"].";;;".$row1["bigint_SupplierID"].";;;".$row1["text_GoogleMapsURL"].";;;".$row1["text_VTigerData"].";;;".$row1["tinyint_VariablePricingEnabled"].";;;".$row1["smallint_SupplierStatus"]);			}		}		mysql_free_result($result1);	}}

all text fields in the database are of utf8_binary collation - so as to case sensitively support utf8.somebody please help!- Pierre.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

in the mysql database, these attribute keys and values are stored as utf8_bin - but the data was entered as ascii - is it possible that a value cannot be matched due to the conversion of collation? there is a dash in some values and these are where it messes up. i notice that there are about 5 dash characters in utf8 - two lengths which can be confused. i am at a total loss here, i have absolutely no concrete clue as to why this would be happening.
I'm confused about what is actually happening (or not happening). But, here's a way to use the debug_backtrace function to generate error messages which include the file and line where the function was called from without needing to pass that to the function itself. This also works if the function you're running has been included in another file, it will still report the file and line number where you executed the function which eventually had an error.
<?phpini_set('display_errors', 1);function do_query($sql){  // do your processing and check for errors  $error = true;  $error_message = 'There was an error';  if ($error)  {	$trace = debug_backtrace();		//var_dump($trace);	$cur = $trace[0];	if (!isset ($cur['file']))	{	  $cur['file'] = '[PHP Kernel]';	}	if (!isset ($cur['line']))	{	  $cur['line'] = '';	}	trigger_error('Error in ' . $cur['function'] . ' from ' . $cur['file'] . '(' . $cur['line'] . '): ' . $error_message, E_USER_ERROR);  }}// the file and line number where the function is called will be used in the error messagedo_query('foo');?>

Link to comment
Share on other sites

okay, i can give some clarity on all data entered into the database.it is entered via ajax post requests, in unicode - now all unicode characters enter the database as utf8, the attribute values were originally ascii (no utf8 characters and apparently still are). it was needed to choose this collation rather than utf8_cirillic_ci, as this is the only one which is case sensitive according to certain sources i had discovered. tomorrow i am to run tests untill all the suppliers have a last sent lead date in the database (currently some have 0000-00-00 00:00:00 as the timestamp, also renaming the suppliers. my client said that he noticed the suppliers swapping not having the anti-attribute pairs matched when he renamed some of the suppliers.i am more importantly going to write all the keys and values checked - to see what is happening. is that if statement correct there with the stristr function? to see if the database anti-attribute keys and values exist within the consumer supplied keys and values.i've tested all the sql statements - and these all run smoothly with recordsets. if there is a recordset returned, then the supplier will only be dropped if the key and value in the database are in a key and value pair submitted by the consumer.will let more be known once the test runs have been done tomorrow.there are no errors, sql or php from what i can see - it is just an anomaly that only one supplier out of 5 for the region is dropped according to anti-attributes. these records are what are selected in the dropattribs function's 2-table joined select.it's just that the code i pasted seems to be behaving rather funky, not as it is supposed to.sincerely,Pierre du Toit.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

I'm still having a hard time understanding, you're describing the problem in terms of your application but I'm not familiar with your application, I don't know what a supplier or "anti-attribute pair" means with regard to the database. If you could describe the problem without using terms specific to your application that may help.There does look like there's at least one issue with the if statement though. You're comparing the output of stristr with false, which makes me think that you're using stristr to check whether or not a string exists in another one. That's not really what that function is for, the return value is usually a string. strstr and stristr will still return a value which evaluates to false in some situations even if the substring exists in the string. If you are specifically testing to see if the string does not exist, use the strict comparison operator to make sure it's returning boolean false and not another value that just evaluates to false. It's also common to use strpos and use strict comparison to compare the return value to false, e.g.:strpos(strtolower(trim($key)), strtolower(strval($row["text_AttributeDescription"]))) !== false

Link to comment
Share on other sites

I'm still having a hard time understanding, you're describing the problem in terms of your application but I'm not familiar with your application, I don't know what a supplier or "anti-attribute pair" means with regard to the database. If you could describe the problem without using terms specific to your application that may help.There does look like there's at least one issue with the if statement though. You're comparing the output of stristr with false, which makes me think that you're using stristr to check whether or not a string exists in another one. That's not really what that function is for, the return value is usually a string. strstr and stristr will still return a value which evaluates to false in some situations even if the substring exists in the string. If you are specifically testing to see if the string does not exist, use the strict comparison operator to make sure it's returning boolean false and not another value that just evaluates to false. It's also common to use strpos and use strict comparison to compare the return value to false, e.g.:strpos(strtolower(trim($key)), strtolower(strval($row["text_AttributeDescription"]))) !== false
yeah i started noticing that stristr was in fact returning empty strings and not false - as even when the output is printed within the strval function, i get an empty string.basically i need to see if the database values (non-attribute pair) are within the the key and value pairs - case insensitive though - from the consumer who submitted the form. so rather do !="" ?
Link to comment
Share on other sites

PS: thanks though for pointing in the right direction :) strpos instead of stristr truly seems to do the trick :)

Link to comment
Share on other sites

sighs...trying to print the data that is checked, i ran into the following problem.

echo mysql_real_escape_string("\r\n\t\t\t\$unset = ".(($unset===true)?"true":"false"));echo mysql_real_escape_string("\r\n\t\t\tstr"."pos(\"".$key."\",\"".$row["text_AttributeDescription"]."\") = ".	((strpos(strtolower(trim($key)),strtolower(strval($row["text_AttributeDescription"]))))!==false)?	strpos(strtolower(trim($key)),strtolower(strval($row["text_AttributeDescription"]))):"false");echo mysql_real_escape_string("\r\n\t\t\t\str"."pos(\"".$value."\",\"".$row["text_AttributeValue"]."\") = ".	((strpos(strtolower(trim($value)),strtolower(strval($row["text_AttributeValue"]))))!==false)?	strpos(strtolower(trim($value)),strtolower(strval($row["text_AttributeValue"]))):"false");

currently returns with the following:

$unset = false00
but i would like to have it print something like the following:
$unset = false strpos("key1","key4") = false strpos("value4","value3") = false
how can one print a function name without executing it in a string? Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

hmmm i attempted to print as follows:

echo mysql_real_escape_string("\r\n\t\t\t\$unset = ".(($unset===true)?"true":"false"));echo mysql_real_escape_string("\r\n\t\t\tstr");echo mysql_real_escape_string("pos(\"".$key."\",\"".$row["text_AttributeDescription"]."\") = ".((strpos(strtolower($key),strtolower($row["text_AttributeDescription"])))!==false)?strpos(strtolower(trim($key)),strtolower($row["text_AttributeDescription"])):"false");echo mysql_real_escape_string("\r\n\t\t\t\str");echo mysql_real_escape_string("pos(\"".$value."\",\"".$row["text_AttributeValue"]."\") = ".((strpos(strtolower($value),strtolower($row["text_AttributeValue"])))!==false)?strpos(strtolower(trim($value)),strtolower($row["text_AttributeValue"])):"false");

but this prints the following:

$unset = false str0 \str0
:/this is returned in a javascript alert - hence the oneline echo'ing.
Link to comment
Share on other sites

okay... the alerted output is as follows:

dropattribs(0)	Continental Canopies (Cape Town)		$GLOBALS["attribsarr"]["canopy_req"] = pre-owned_white		$GLOBALS["attribsarr"]["canopy_style"] = lowline_luxury		$GLOBALS["attribsarr"]["budget"] = R12,500 plus		$GLOBALS["attribsarr"]["fitment"] = ASAP		$GLOBALS["attribsarr"]["vehicle_status"] = possession_no_shopping		$GLOBALS["attribsarr"]["vehicle_make_model"] = Toyota - LWB		$GLOBALS["attribsarr"]["year_model"] = 2010	Just Canopies (Cape Town)		$GLOBALS["attribsarr"]["canopy_req"] = pre-owned_white		$GLOBALS["attribsarr"]["canopy_style"] = lowline_luxury		$GLOBALS["attribsarr"]["budget"] = R12,500 plus		$GLOBALS["attribsarr"]["fitment"] = ASAP		$GLOBALS["attribsarr"]["vehicle_status"] = possession_no_shopping		$GLOBALS["attribsarr"]["vehicle_make_model"] = Toyota - LWB		$GLOBALS["attribsarr"]["year_model"] = 2010	Canopymart (Bellville)		$GLOBALS["attribsarr"]["canopy_req"] = pre-owned_white		$GLOBALS["attribsarr"]["canopy_style"] = lowline_luxury		$GLOBALS["attribsarr"]["budget"] = R12,500 plus		$GLOBALS["attribsarr"]["fitment"] = ASAP		$GLOBALS["attribsarr"]["vehicle_status"] = possession_no_shopping		$GLOBALS["attribsarr"]["vehicle_make_model"] = Toyota - LWB		$GLOBALS["attribsarr"]["year_model"] = 2010	Roamer Rand Cape (Retreat)		$GLOBALS["attribsarr"]["canopy_req"] = pre-owned_white[color="#FF0000"]			$unset = false			strpos("canopy_req","canopy_req") = 0			strpos("pre-owned_white","pre-owned_white") = 0[/color]		$GLOBALS["attribsarr"]["canopy_style"] = lowline_luxury		$GLOBALS["attribsarr"]["budget"] = R12,500 plus		$GLOBALS["attribsarr"]["fitment"] = ASAP		$GLOBALS["attribsarr"]["vehicle_status"] = possession_no_shopping		$GLOBALS["attribsarr"]["vehicle_make_model"] = Toyota - LWB		$GLOBALS["attribsarr"]["year_model"] = 2010	Stingray Canopies (Cape Town)		$GLOBALS["attribsarr"]["canopy_req"] = pre-owned_white[color="#FF0000"]			$unset = false			strpos("canopy_req","canopy_req") = 0			strpos("pre-owned_white","pre-owned_white") = 0[/color]		$GLOBALS["attribsarr"]["canopy_style"] = lowline_luxury		$GLOBALS["attribsarr"]["budget"] = R12,500 plus		$GLOBALS["attribsarr"]["fitment"] = ASAP		$GLOBALS["attribsarr"]["vehicle_status"] = possession_no_shopping		$GLOBALS["attribsarr"]["vehicle_make_model"] = Toyota - LWB		$GLOBALS["attribsarr"]["year_model"] = 2010dropattribs(2)dropattribs(4)

in the function as follows:

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 = 0; $i < count($GLOBALS[$sarray]); $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]);		foreach ($GLOBALS["attribsarr"] as $key => $value) {								// begin iterate form attributes			$unset = false;												// reset the unset flag			// select current attribute key and bound values for supplier that are 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				while ($row = mysql_fetch_array($result)) {							// begin while suppliers !attribs					// begin if db key and value in attrib key and value					//echo mysql_real_escape_string("\r\n\t\t\t\$unset = ".(($unset===true)?"true":"false"));					//echo mysql_real_escape_string("\r\n\t\t\tstrpos");					//	echo mysql_real_escape_string("(\"".$key."\",\"".$row["text_AttributeDescription"]."\") = ");					//	echo mysql_real_escape_string((strpos(strtolower($key),strtolower($row["text_AttributeDescription"]))!==false)?					//		strpos(strtolower(trim($key)),strtolower($row["text_AttributeDescription"])):"false");					//echo mysql_real_escape_string("\r\n\t\t\tstrpos");					//	echo mysql_real_escape_string("(\"".$value."\",\"".$row["text_AttributeValue"]."\") = ");					//	echo mysql_real_escape_string((strpos(strtolower($value),strtolower($row["text_AttributeValue"]))!==false)?					//		strpos(strtolower(trim($value)),strtolower($row["text_AttributeValue"])):"false");[color="#FF0000"]					if (!$unset &&										// if hasn't unset yet						strpos(strtolower(trim($key)),						 	// if key does not exist in db						 strtolower(strval($row["text_AttributeDescription"]))) !== false &&		// "						strpos(strtolower(trim($value)),						// if value does not exist in db						 strtolower(strval($row["text_AttributeValue"]))) !== false) {			// "							[color="#9932CC"]unset($GLOBALS[$sarray][$i]);						// drop the supplier from the array[/color]							$unset = true;								// set unset flag to true					}											// end if key & value in db[/color]				}												// 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}

i have commented the echo'ing code which is then displayed as the abovementioned javascript alert, but it does not drop all the unmatched suppliers from the first array (active suppliers, status 0). the code in red is what does not seem to be happening when it should. any ideas? the line in purple is supposed to be unset if this condition is met, it is met twice as proven by the values alerted.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

unset($GLOBALS[$sarray][$i]);

is only unsetting the first time it is called from within a function on an array outide the function (page level),is there perhaps a way to always remove an element from an array?

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 = 0; $i < count($GLOBALS[$sarray]); $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]);		foreach ($GLOBALS["attribsarr"] as $key => $value) {								// begin iterate form attributes			$unset = false;												// reset the unset flag for this iteration			// 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					$unset = true;										// set unset flag to true				}													// 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}

well i have rather attempted matching the individual keys and values against the supplier - if found in the database, it is supposed to be dropped.unfortunately - unset only works the first time it is used. why would this be?

Link to comment
Share on other sites

okay. unsetting elements from an array while looping it, seems to be the problem here. how would i be able to loop through the array, unsetting the items in it?after a quick google, i found this: Deleting Elements from an Array (PHP Cookbook)my question would be now, however - how can i save these variable, noncontiguous references ($i) to unset them all at once at the end of the loop?the example given was

function dropattribs($status) {[color="#FF0000"]	switch ($status) {		case 2:			$sarray = "mailaddp";											// prospecting status 2			break;		case 4:			$sarray = "mailaddl";											// listed status 4			break;		default:			$sarray = "mailadds";											// active status 0	}[/color]	//echo mysql_real_escape_string("\r\ndropattribs(".$status.")");[color="#2E8B57"]	for ($i = 0; $i < count($GLOBALS[$sarray]); $i++) {		$sdata = $GLOBALS[$sarray][$i];											// get supplier data		$arr = split(";;;",$sdata);												// split supplier array		$sid = $arr[6];[/color]													// get supplier id		//echo mysql_escape_string("\r\n\t".$arr[1]);		foreach ($GLOBALS["attribsarr"] as $key => $value) {								// begin iterate form attributes			// select current attribute key and value for supplier that is not supported[color="#FF8C00"]			$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);[/color]			//echo mysql_real_escape_string("\r\n\t\t\$GLOBALS[\"attribsarr\"][\"".$key."\"] = ".$value);[color="#FF00FF"]			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				}													// end while suppliers !attributes				mysql_free_result($result);										// free mysql result after looping			}														// end if mysql result[/color]		}															// end iterate form attributes	}																// end iterate suppliers array}

red code determines the array to parse and remove from.green code gets the supplier id from the arrayorange code checks if the current key and value from the attributes array are set against the supplier in the database.magenta code is supposed to remove the specific elements from the array. (but with this code, it only works the first time)

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

success at last :) I iterate through the suppliers array’s now in reverse, removing elements as I find them :)the unset function now DROPS all the elements encountered in the suppliers arrays that should not be there :)this issue is now RESOLVED!

Link to comment
Share on other sites

indeed - there is so much for us all to learn :)justsomeguy pointed me in the right direction with regards to finding the solution in the end :) at least i don't depend on others to get things done! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...