Jump to content

Greywacke

Members
  • Posts

    510
  • Joined

  • Last visited

Everything posted by Greywacke

  1. ah not sure exactly what was done wrong, but it was most probably an unescaped quote, if not an overescaped quote.it's working now issue RESOLVED
  2. hmmm forgot all about the MOD operator... :)and amazingly, there is something that i still do not see (the % shows as part of the string in php - escaping them doesn't help either, that the first bit of the composed string evaluates to 0. :)could somebody please tell me what i do not see!sighs...
  3. hi,i am rather rattled at this. can't seem to get any results on the web though... <?php/*Quicktext Pro AJAX XML RESPONSEVersion 2.2.3*///set_time_limit(0);//return consumer name and product description by emailinclude("../includes/content/dwtphovu_f3rr37y.php");$eml = $_GET["q"];if ($eml == "") { $eml = "@"; }header("Content-type: text/xml; charset=utf-8");echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";echo "<root>\n";$tsql = "SELECT SUBSTRING_INDEX( text_Consumer, \";\", 1 ) AS text_ConsumerName, IF( LOCATE( \"products_description\", text_LeadAttributes ) = 0 , CONCAT_WS( " - ", SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, \"<br />\", 6 ), \";\", -1 ), \" = \", -1 ), SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, \"<br />\", 2 ), \";\", -1 ), \" = \", -1 ) ) , SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, \"<br />\", 1 ), \" = \", -1 ) ) AS text_ProductDescription FROM 6_serviceleads WHERE text_Consumer LIKE \"%".$eml."%\" ORDER BY timestamp_LeadCreated DESC LIMIT 1;"; echo " ".$tsql."\n";$result = mysql_query_errors($tsql , $conn , __FILE__ , __LINE__ , true);if ($result) { while ($row = mysql_fetch_array($result)) { echo " <lead consumername=\"". xmlentities($row["text_ConsumerName"]). "\" productdescription=\"". xmlentities($row["text_ProductDescription"]). "\" />\n"; } mysql_free_result($result);}echo " <sql>".join("\n",$sql)."</sql>\n";echo "</root>";mysql_close($conn);?> that's the code, what is going on here that i do not see? at the moment it returns the following xml. <?xml version="1.0" encoding="utf-8" ?><root> 0gcm.nationsu@gmail.com%" ORDER BY timestamp_LeadCreated DESC LIMIT 1; <sql></sql></root> that email address after the 0 was sent as the q value in the querystring - here is the page:QuickText Pro Variable Retrieval
  4. awesome ^^i had the AS thingy inside the if function, it was supposed to be outside and only once. SELECT SUBSTRING_INDEX( text_Consumer, ";", 1 ) AS text_ConsumerName, IF( LOCATE( "products_description", text_LeadAttributes ) = 0 , CONCAT_WS( " - ", SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 6 ), ';', -1 ), ' = ', -1 ), SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 2 ), ';', -1 ), ' = ', -1 ) ) , SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 1 ), ' = ', -1 ) ) AS text_ProductDescriptionFROM 6_serviceleads WHERE text_Consumer LIKE "%hayward@telkomsa.net%" OR text_Consumer LIKE "%gcm.nationsu@gmail.com%"; this issue is now RESOLVED
  5. okay, there were a few things wrong with it... i've edited the query as follows (let the IF() function only return one field): SELECT SUBSTRING_INDEX( text_Consumer, ";", 1 ) AS text_ConsumerName, IF( LOCATE( text_LeadAttributes, "products_description" ) = 0 , CONCAT( SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, "<br />", 6 ), ";", -1 ), " = ", -1 ), " - ", SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, "<br />", 2 ), ";", -1 ), " = ", -1 ) ) AS text_ProductDescription , SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, "<br />", 1 ), " = ", -1 ) AS text_ProductDescription ) FROM 6_serviceleads WHERE text_Consumer LIKE "%hayward@telkomsa.net%" OR text_Consumer LIKE "%gcm.nationsu@gmail.com%" with the following error:
  6. the matching records for these two e-mails in the table 6_serviceleads are: [b]bigint_LeadID[/b] [b]text_Consumer[/b][color="#FF0000"]725 Tony Hayward;tony.hayward@telkomsa.net; 0843720330;Pretoria[/color][color="#008000"]720 Tony Hayward;tony.hayward@telkomsa.net; 0843720330;Pretoria[/color][color="#0000FF"]3064 Lazarus Munetsi;gcm.nationsu@gmail.com; 0760270022;Pretoria[/color][b]text_LeadAttributes[/b][color="#FF0000"]products_description = Opel Corsa Canopy - Lowline<br />Bakkie model = 2004 - current model<br />Requirement = Pre-owned - White<br />Colour code = White Non-coded (standard)<br />Budget = R3,000 to R4,000<br />Fitment = ASAP[/color][color="#008000"]products_description = Opel Corsa Canopy - Lowline<br />Bakkie model = 2004 - current model<br />Requirement = Pre-owned - White<br />Colour code = White Non-coded (standard)<br />Budget = R3,000 to R4,000<br />Fitment = ASAP[/color][color="#0000FF"]canopy_req = pre-owned_colour_coded<br />canopy_style = lowline_luxury<br />budget = R4,000 to R5,000<br />fitment = within_3_months<br />vehicle_status = possession_yes<br />vehicle_make_model = Mitsubishi - DCAB<br />year_model = 2005[/color][b]text_LeadMessage[/b][color="#FF0000"]I need a canopy for a new shape corsa utility bakkie asap.[/color][color="#008000"]I need a canopy for a new shape corsa utility bakkie asap.[/color][color="#0000FF"]NULLSTR[/color][b]bigint_ServiceID[/b] [b]bigint_SupplierID[/b] [b]bigint_RegionID[/b][color="#FF0000"]1 17 24[/color][color="#008000"]1 23 24[/color][color="#0000FF"]1 23 24[/color][b]tinyint_LeadSent[/b] [b]timestamp_LeadCreated[/b][color="#FF0000"]1 2010-02-25 07:49:57[/color][color="#008000"]1 2010-02-25 07:49:57[/color][color="#0000FF"]1 2010-07-08 03:51:34[/color] however, i need to select the concatenation of substring vehicle_make_model, " - " and canopy_style if the record is from source a, and the substring products_description if from source b. something is wrong with the query i posted, but i'm afraid i cannot see what.
  7. unfortunately, i cannot seem to see the forest for the trees here...
  8. seperately, they work however: SELECT SUBSTRING_INDEX( text_Consumer, ";", 1 ) AS text_ConsumerName, CONCAT( SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 6 ), ';', -1 ), ' = ', -1 ), " - ", SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 2 ), ';', -1 ), ' = ', -1 ) ) AS text_ProductDescription FROM 6_serviceleads WHERE text_Consumer LIKE "%gcm.nationsu@gmail.com%" LIMIT 1; for records from the first source, and SELECT SUBSTRING_INDEX( text_Consumer, ";", 1 ) AS text_ConsumerName, SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 1 ), ' = ', -1 ) AS text_ProductDescription FROM 6_serviceleads WHERE text_Consumer LIKE "%hayward@telkomsa.net%" LIMIT 1; for records from the second source, each return one consumer name and product description.
  9. hi there,as you have probably seen by now, the records are entered from two different sources. therefore, the sets of values saved as text, are not always the same. therefore i have tried to combine the two selects for each source, using the following SELECT IF statement. SELECT IF( ( LOCATE( text_LeadAttributes, "products_description" ) = 0 ), ( SUBSTRING_INDEX( text_Consumer, ";", 1 ) AS text_ConsumerName, CONCAT( SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 6 ), ';', -1 ), ' = ', -1 ), " - ", SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 2 ), ';', -1 ), ' = ', -1 ) ) AS text_ProductDescription ), ( SUBSTRING_INDEX( text_Consumer, ";", 1 ) AS text_ConsumerName, SUBSTRING_INDEX( SUBSTRING_INDEX( text_LeadAttributes, '<br />', 1 ), ' = ', -1 ) AS text_ProductDescription ) ) FROM 6_serviceleads WHERE text_Consumer LIKE "%hayward@telkomsa.net%" OR text_Consumer LIKE "%gcm.nationsu@gmail.com%" LIMIT 1; however, when i run this query in PMA - it returns with the following: i will attempt figuring this out myself, but please feel welcome to give it a shot
  10. thanks dsoneuk,it was not exactly offsetHeight though that was causing the warning, i added + 'px' in everywhere where it was expected (where the css values for the dimentional and positioning are set), and those warnings are gone :)as i said this is not originally my code... :)issue has now been RESOLVED!
  11. i've got firebug 1.5.4 but i couldn't seem to find a reference on how to use it, and where to look for the errors. :)there was a mistake where the onmouseover event is set for the list values, there was a ; at the end - and i am not used to coding events like that. i will look into the offsetHeight.
  12. hi there,i have managed to keep the scripts clean of these since i started development for the current client since december 2009.however, he has requested an auto-complete functionality, and for this i added the phpguru one, which seems to work the best.however - the one function, displayed below - causes the warning below the function to display in the error console.the function: function AutoComplete_ShowDropdown(id) { AutoComplete_HideAll(); var value = __AutoComplete[id]['element'].value; var toDisplay = new Array(); var newDiv = null; var text = null; var numItems = __AutoComplete[id]['dropdown'].childNodes.length; // Remove all child nodes from dropdown while (__AutoComplete[id]['dropdown'].childNodes.length > 0) { __AutoComplete[id]['dropdown'].removeChild(__AutoComplete[id] ['dropdown'].childNodes[0]); } // Go thru data searching for matches for (i=0; i<__AutoComplete[id]['data'].length; ++i) { var lval = __AutoComplete[id]['data'][i].toLowerCase(); if (lval.substr(0, value.length) == value.toLowerCase()) { toDisplay[toDisplay.length] = __AutoComplete[id]['data'][i]; } } // No matches? if (toDisplay.length == 0) { AutoComplete_HideDropdown(id); return; } // Add data to the dropdown layer for (i=0; i<toDisplay.length; ++i) { newDiv = document.createElement('div'); newDiv.className = 'autocomplete_item'; // no use setAttribute() newDiv.setAttribute('id', 'autocomplete_item_' + i); newDiv.setAttribute('index', i); newDiv.style.zIndex = '299'; // Scrollbars are on display ? if (toDisplay.length > __AutoComplete[id]['maxitems'] && navigator.userAgent.indexOf('MSIE') == -1) { newDiv.style.width = __AutoComplete[id]['element']. offsetWidth - 22 + 'px'; } newDiv.onmouseover = function() {AutoComplete_HighlightItem( __AutoComplete[id]['element'].getAttribute('id'), this. getAttribute('index'));} newDiv.onclick = function() {AutoComplete_SetValue( __AutoComplete[id]['element'].getAttribute('id') ); AutoComplete_HideDropdown(__AutoComplete[id]['element']. getAttribute('id'));} text = (toDisplay[i])?toDisplay[i]:" "; newDiv.innerHTML = text; __AutoComplete[id]['dropdown'].appendChild(newDiv); } // Too many items? if (toDisplay.length > __AutoComplete[id]['maxitems']) { __AutoComplete[id]['dropdown'].style.height = (__AutoComplete[id] ['maxitems'] * 15) + 2 + 'px'; } else { __AutoComplete[id]['dropdown'].style.height = ''; } /** * Set left/top in case of document movement/scroll/window resize etc */ __AutoComplete[id]['dropdown'].style.left = AutoComplete_GetLeft( __AutoComplete[id]['element'] ); __AutoComplete[id]['dropdown'].style.top = AutoComplete_GetTop( __AutoComplete[id]['element'] ) + __AutoComplete[id]['element'].offsetHeight; // Show the iframe for IE if (isIE) { __AutoComplete[id]['iframe'].style.top = __AutoComplete[id] ['dropdown'].style.top; __AutoComplete[id]['iframe'].style.left = __AutoComplete[id] ['dropdown'].style.left; __AutoComplete[id]['iframe'].style.width = __AutoComplete[id] ['dropdown'].offsetWidth; __AutoComplete[id]['iframe'].style.height = __AutoComplete[id] ['dropdown'].offsetHeight; __AutoComplete[id]['iframe'].style.visibility = 'visible'; } // Show dropdown if (!__AutoComplete[id]['isVisible']) { __AutoComplete[id]['dropdown'].style.visibility = 'visible'; __AutoComplete[id]['isVisible'] = true; } // If now showing less items than before, reset the highlighted value if (__AutoComplete[id]['dropdown'].childNodes.length != numItems) { __AutoComplete[id]['highlighted'] = null; }} warning displayed: Warning: Error in parsing value for 'top'. Declaration dropped.Source File: http://www.intellisource.co.za/test_8347379386/?p=3Line: 0 i understand that these are css errors, but how could i find out why the 'top' decleration is not being allowed? 0othere are no strings shown, but css values are set in the function above. the only browser compatibility this site needs to have is firefox, as this is the administration website.
  13. 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.
  14. 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.
  15. no, the individual values need to be inserted into the mysql table. i believe you need to include or require the functions into your php document somehow, the MPQ document is the reference to these functions. as described below, you will need to construct a MySQL INSERT statement to insert the values into your table. :)i would create the variables for this as $valuename = functionname(); (following the MPQ reference of course), in the PHP after the file has been uploaded and opened, where it is parsed.you will be able to retrieve these values later, perhaps if you intend on keeping a store of the files on the server - to keep a path to the file in each record as another field - unless you want to delete the files after parsing them and inserting the values into the mysql database.upon retrieval, these values can then be compiled from the database into a new file, and made available for download.
  16. double quotes seem to work best as string delimiters, however i only use the backtick as keyword delimiters if they contain a - or space. the backtick is invalid outside of a string value though. in sql queries backticks only work for keyword delimiters, and not for string values. i personally just escape the double quotes when used in queries inside php strings that are enclosed by double quotes.as for the double quotes, even in generated xml and html and query strings, i seem to use far less single quotes. despite using double quotes, i do not however, embed variables within them. just escape the double quotes and $ symbols within strings.seems to work best for me, i have been coding this way my entire life - and changing an old habit that works is not always a good idea.to add to the acknowledgment about notepad++, as well as certain other development applications and even script color coding over the net - double quotes to enclose strings in php are better supported.i believe the majority use double quotes in html attributes, xml attributes and php strings - i have not had a look at the vote results yet
  17. 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.
  18. awesome :)i have successfully moved the rest of the validation and the second ajax request to the ajax response for the first request. it works successfully without hanging the browser :)thanks a mill justsomeguy, for pointing me in the right direction :)this issue is now RESOLVED
  19. thanks again justsomeguy, i was starting to think in that direction - but not exactly sure of what i needed to do. i will do these changes in the morning and reply with the results
  20. sighs... unfortunately the ajax here needs to be developed individually. the script is working - has always been working, just how could i make the recently added script wait till the hidden fields value is not -1, then continue with script without hanging the browser (wait for an ajax request to complete before completing validation and submitting the post request) for the modify button's onclick event?
  21. hi there,sitting with a slight issue here. an ajax post request is sent after form validation, and i need to retrieve the latest value from the database to compare against with form validation.at the moment i just inserted an ajax request... looping till the hidden field gets the updated value, and continuing validating it. however - there is a problem with this method - if the internet is slow (bandwidth is limited for whatever reason), it hangs the browser 0ohere is the excerpt from the current script, inserted after validating the other fields: makeRequest("GET", "scripts/ajax_suppliers.php?q=9&s="+document.form_suppliers.list_suppliers.options[document.form_suppliers.list_suppliers.selectedIndex].value.split(";,;")[0], "");while (document.form_suppliers.hidden_creditbalance.value == "-1") { // wait till hidden balance is updated}var fb = parseInt(document.form_suppliers.text_creditbalance.value);var cb = parseInt(document.form_suppliers.hidden_creditbalance.value);var reason = "";if (fb != cb && cb != -1) { if (!confirm(trim(document.form_suppliers.list_suppliers.options[document.form_suppliers.list_suppliers.selectedIndex].text.split(" - ")[0]) + " has a current balance of " + cb + " PAYG Credits.\n" + "Adjust this balance to reflect " + fb + " PAYG Credits?")) { document.getElementById("ajaxbg").style.visibility = "hidden"; document.form_suppliers.text_creditbalance.focus(); return false; } else { reason = prompt("Please enter a reason for updating credits.", ""); }} here are the makeRequest and alertContents function on this page, which now includes support for just the cbal tag. function makeRequest(method, url, parameters) { var http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type http_request.overrideMimeType('text/xml'); //http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { salert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = function() { alertContents(http_request); } url += (method=="GET")?parameters:""; http_request.open(method, url, true); if (method == "POST") { http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-length", parameters.length); http_request.setRequestHeader("Connection", "close"); } http_request.send((method=="GET")?null:parameters); ajaxloading++;}// xml parserfunction alertContents(http_request) { if (http_request.readyState == 4) { // filter state changed if (http_request.status == 200) { // filter errors var xmldoc = http_request.responseXML; // get response //salert(http_request.responseText); // salert xml data var cb = false; // current balance flag var stats = false; // get timeframe info var arrTF = new Array(); var rows1 = xmldoc.getElementsByTagName("timeframe"); for (var rr = 0; rr < rows1.length; rr++) { if (rows1[rr].attributes) { arrTF[0] = rows1[rr].attributes.getNamedItem("name").nodeValue; arrTF[1] = rows1[rr].attributes.getNamedItem("value").nodeValue; } } // parse records var x = 0; var arrStats = new Array(); var rows2 = xmldoc.getElementsByTagName("statistics"); for (var r = 0; r < rows2.length; r++) { var records = rows2[r].getElementsByTagName("record"); if (rows2[r].attributes) { arrStats[x] = rows2[r].attributes.getNamedItem("name").nodeValue; x++; } for (var c = 0; c < records.length; c++) { var record = records[c]; if (record.attributes) { arrStats[x] = new Array(); arrStats[x][0] = record.attributes.getNamedItem("statname").nodeValue; if (arrTF[0] != "timeframe_top10transactions") { arrStats[x][1] = record.attributes.getNamedItem("leads").nodeValue; } else { arrStats[x][1] = record.attributes.getNamedItem("amount").nodeValue; } x++; } } stats = true; } if (stats) insertstats(arrTF,arrStats); var rows = xmldoc.getElementsByTagName("supplier"); for (var r = 0; r < rows.length; r++) { var i = 0; var arr = new Array(); var aa = 0; var arr1 = new Array(); var sa = 0; var arr3 = new Array(); var lc = 0; var arr5 = new Array(); for (var c = 0; c < rows[r].childNodes.length; c++) { var supplierdetail = rows[r].childNodes[c]; if (supplierdetail.childNodes.length > 0) { arr[i] = (supplierdetail.firstChild.data==" ")?"":supplierdetail.firstChild.data; i++; } else if (supplierdetail.nodeName == "serviceattrib") { var arr2 = new Array(); for (var a = 0; a < supplierdetail.attributes.length; a++) { arr2[a] = supplierdetail.attributes[a].value; } arr1[aa] = arr2.join(";:;"); aa++; } else if (supplierdetail.nodeName == "supplierattrib") { var arr4 = new Array(); for (var s = 0; s < supplierdetail.attributes.length; s++) { arr4[s] = supplierdetail.attributes[s].value; } arr3[sa] = arr4.join(";:;"); sa++; } else if (supplierdetail.nodeName == "lcmp") { var arr6 = new Array(); for (var q = 0; q < supplierdetail.attributes.length; q++) { arr6[q] = supplierdetail.attributes[q].value; } arr5[lc] = arr6.join(";:;"); lc++; } } arr[i] = arr1.join(";.;"); // available supplier attributes i++; arr[i] = arr3.join(";.;"); // selected supplier attributes i++; arr[i] = arr5.join(";.;"); // linked leads 360 lead 360 campaigns i++; //salert(arr); if (arr) addrecord("list_suppliers", arr); } var catg = xmldoc.getElementsByTagName("pcats"); for (var g = 0; g < catg.length; g++) { var cats = catg[g].getElementsByTagName("pcat"); var n = 0; var arrpc = new Array(); for (var p = 0; p < cats.length; p++) { var cat = cats[p]; if (cat.attributes) { arrpc[n] = new Array(); for (var o = 0; o < cat.attributes.length; o++) { arrpc[n][o] = cat.attributes[o].value; } n++; } } addcategories(arrpc); } // update current balance if (xmldoc.getElementsByTagName("cbal")[0]) { if (xmldoc.getElementsByTagName("cbal")[0].firstChild) { var cbal = xmldoc.getElementsByTagName("cbal")[0].firstChild.data; if (cbal != undefined) { document.form_suppliers.hidden_creditbalance.value = cbal; cb = true; } } } // mysql queries / failures if (xmldoc.getElementsByTagName("sql")[0]) { if (xmldoc.getElementsByTagName("sql")[0].firstChild) { var sql = xmldoc.getElementsByTagName("sql")[0].firstChild.data; if (sql != undefined) { salert(sql); } } } } else { salert('There was a problem with the request.'); } if (!cb) { document.form_suppliers.list_suppliers.selectedIndex = supplier; document.form_suppliers.list_suppliers.onchange(); } ajaxloading--; sessrem = sesstot; if (ajaxloading <= 0 && !cb) document.getElementById("ajaxbg").style.visibility = "hidden"; }} the xmlrequest document sends the balance for the supplier's id in the querystring. however, if the net is slow (limited bandwidth), it hangs the browser.is there perhaps a smarter way to do this, the first script is called within the onclick event for the modify button. i cannot wait a specific amount of time and the validation and post request need to continue after the balance validation has been completed.
  22. 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!
  23. 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!
  24. 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)
  25. 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?
×
×
  • Create New...