Jump to content

some issues regarding stristr: non-attributes not dropping array elements


Greywacke
 Share

Recommended Posts

hi again,i've developed the following function to drop the suppliers by attributes they do not support from the array retrieved by region.

function dropattribs($status) {	// status 0 (active) and 2 (prospecting)	foreach ($GLOBALS[				// begin iterate suppliers array				($status==0)?				"mailadds":				"mailaddp"] as $i => $mailadd) {		$arr = split(";;;",$mailadd);		// get supplier id		$sid = $arr[6];		// begin iterate form attributes		foreach ($GLOBALS["attribsarr"] as $key => $value) {			// select current attribute key and bound values			// for supplier that are not requirements			$tsql = "SELECT * FROM 9_supplierattributes 				JOIN (3_serviceattributes) 				ON (					9_supplierattributes.bigint_AttributeID = 					3_serviceattributes.bigint_AttributeID				   ) 				WHERE 					3_serviceattributes.text_AttributeDescription LIKE 						\"%".$key."%\" AND 					3_serviceattributes.bigint_AttributeServiceID = 						".$GLOBALS["service"]." AND 					9_supplierattributes.bigint_SupplierID = 						".$sid.";";			$result = mysql_query_errors($tsql, $conn , __FILE__ , __LINE__ , false);			if ($result) {				// begin if mysql result				// begin while suppliers !attribs				while ($row = mysql_fetch_array($result)) {					// begin if db value in attrib value					[b]if (stristr($value,$row["text_AttributeValue"])!=							FALSE) {[/b]						// drop current $i from $mailadds/p array						unset($GLOBALS[($status==0)?							"mailadds":"mailaddp"][$i]);					}		// end if db value in attrib value				}			// end while suppliers !attributes			}				// end if mysql result			mysql_free_result($result);	// free sql result		}					// end iterate form attributes	}						// end iterate suppliers array}

it is supposed to iterate the suppliers arraythen within that iterate the form attributes, which are successfully retrieved (can see that from enabling sql logging in the mysql_query_errors function.)for each form attribute, i attempt selecting the attributes and values from the attributes set against each supplier. if it gets a match, it checks that attribute value for the nonvalue selected from the db.if found, it is supposed to drop the suppliers array element. but it does not, what could be wrong here?the line in bold, the case insensitive stristr check, seems to be the problem.running a test query in pma of the database with the following string matches a few nonattributes:

SELECT * FROM 9_supplierattributes JOIN (3_serviceattributes) ON (9_supplierattributes.bigint_AttributeID = 	3_serviceattributes.bigint_AttributeID) WHERE 	3_serviceattributes.text_AttributeDescription LIKE "%vehicle_make_model%" 	AND 	3_serviceattributes.bigint_AttributeServiceID = 1 	AND 	9_supplierattributes.bigint_SupplierID = 36;

one of them is DCAB which is supposed to be detected in the value received from the form, Toyota - DCAB, yet it is not and the supplier gets included in the prospecting array ($mailaddp) when it is mailed.okay, after a bit of reading up - i've changed the if statement to check it not against FALSE for removing.

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

i've tested the handler again, after deleting the one on the server, uploading the updated one, submitting the form again with Toyota - DCAB as the vehicle_make_model attribute.however, the vehicle_make_model = DCAB attribute which was linked to the supplier Roamerrand - does not cause Roamerrand to get unset from the array.somebody please help!the recordset checked for Roamerrand (supplier id 36), is as follows:

bigint_SupplierID	bigint_ServiceID	bigint_Regionid	bigint_AttributeID	bigint_AttributeIDtext_AttributeDescription	text_AttributeValue	bigint_AttributeServiceID36	1	28	308	308	vehicle_make_model	Asiawing	136 	1 	28 	384 	384 	vehicle_make_model 	CCAB 	136 	1 	28 	309 	309 	vehicle_make_model 	Chana 	136 	1 	28 	381 	381 	vehicle_make_model 	DCAB 	136 	1 	28 	370 	370 	vehicle_make_model 	Fiat 	136 	1 	28 	371 	371 	vehicle_make_model 	Ford - F250 	136 	1 	28 	373 	373 	vehicle_make_model 	GMW 	136 	1 	28 	372 	372 	vehicle_make_model 	Gonow 	136 	1 	28 	385 	385 	vehicle_make_model 	KCAB 	136 	1 	28 	387 	387 	vehicle_make_model 	L/Cruiser 	136 	1 	28 	374 	374 	vehicle_make_model 	Mahindra 	136 	1 	28 	307 	307 	vehicle_make_model 	Meiya 	136 	1 	28 	353 	353 	vehicle_make_model 	Nissan - Navara 	136 	1 	28 	354 	354 	vehicle_make_model 	Nissan - Patrol 	136 	1 	28 	356 	356 	vehicle_make_model 	Proton - Arena 	136 	1 	28 	383 	383 	vehicle_make_model 	SCAB 	136 	1 	28 	388 	388 	vehicle_make_model 	Soyat 	136 	1 	28 	357 	357 	vehicle_make_model 	Ssangyong - Musso DCAB 	136 	1 	28 	386 	386 	vehicle_make_model 	Tata - Telcoline 	136 	1 	28 	378 	378 	vehicle_make_model 	Tata - Xenon 	136 	1 	28 	369 	369 	vehicle_make_model 	Volkswagen - Transporter 	1

i noticed that the returned result has 2 duplicate fields AttributeID. and ServiceID.i've located the following page too:but i am unsure if this would be a viable option to use instead of unset, if that is the issue here.http://www.bin-co.com/php/scripts/array_remove.php

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

okay, i've updated the function as follows:

function dropattribs($status) {	// status 0 and 2	foreach ($GLOBALS[($status==0)?"mailadds":"mailaddp"] as $i => $mailadd) {	// begin iterate suppliers array		$arr = split(";;;",$mailadd);											// get supplier id		$sid = $arr[6];		foreach ($GLOBALS["attribsarr"] as $key => $value) {					// begin iterate form attributes			// select current attribute key and bound values for supplier that are not requirements			$tsql = "SELECT 3_serviceattributes.text_AttributeValue FROM 9_supplierattributes JOIN (3_serviceattributes) ON (9_supplierattributes.bigint_AttributeID = 3_serviceattributes.bigint_AttributeID) WHERE 3_serviceattributes.text_AttributeDescription LIKE \"%".$key."%\" 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);			if ($result) {														// begin if mysql result				while ($row = mysql_fetch_array($result)) {						// begin while suppliers !attribs					if (stristr($value,$row["text_AttributeValue"]) != FALSE) {	// begin if db value in attrib value						// drop current $i from $mailadds/p array						unset($GLOBALS[($status==0)?"mailadds":"mailaddp"][$i]);					}															// end if db value in attrib value				}																// end while suppliers !attributes			}																	// end if mysql result			mysql_free_result($result);		}																		// end iterate form attributes	}																			// end iterate suppliers array}

this results from the sql query is the following recordset as tested in PMA:

[b]text_AttributeValue[/b]KCABGonowGMWFiatFord - F250DCABChanaCCABAsiawingL/CruiserMahindraMeiyaNissan - NavaraNissan - PatrolProton - ArenaSCABSsangyong - Musso DCABSoyatTata - TelcolineTata - XenonVolkswagen - Transporter

now to test. then if it still does not work, i've got to make sure that the loops are correct.

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

rofl i can laugh at myself at times like this ^^there was nothing wrong with the function itsself, the problem was with the way it was called for the attributes :)it was called as dropattribs(0) (for active suppliers) instead of dropattribs(2) (for prospecting suppliers) :)this issue has been resolved :)

Edited by Pierre 'Greywacke' du Toit
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...