Jump to content

Greywacke

Members
  • Posts

    510
  • Joined

  • Last visited

Everything posted by Greywacke

  1. hi there,many of you have told me to use multidimentional arrays rather than strings which are later split... i would like to know why this is so, i suspect it has something to do with the problem i am having at the moment. in the first stages of this handler, it worked perfectly - but now it's dropping the last two items of the array.the array is created by going through requirements and if meeting them, it is included like follows: array_push( $GLOBALS[($status==2)?"mailaddp":"mailadds"], $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"].";;;". $row["text_GoogleMapsURL"].";;;". $row["text_VTigerData"]); then later in the code, when testing this array ($mailadds and $mailaddp, where they are used) it outputs the split strings as follows: getsuppliers($service,0); (returns $mailadds array by [b]$recipient = split(";;;",$add);[/b]): $mailadds[0] $recipient[0]=Riette Bradford $recipient[1]=Test Supplier Three $recipient[2]=pierre@greywacke.co.za $recipient[3]=9880 $recipient[4]=27729154799 $recipient[5]=Supreme Industrial Park, Unit F 25, Cnr. Heidelberg Road & Southern Klipriviersberg Road, Steeledale, Johannesburg $recipient[6]=20 $recipient[7]= $recipient[8]=getsuppliers($service,2); (returns $mailaddp array by [b]$recipient = split(";;;",$add);[/b]): $mailaddp[0] $recipient[0]=Riëtte Bradford $recipient[1]=Test Supplier One $recipient[2]=pierre@greywacke.co.za $recipient[3]=9960, $recipient[4]=27729154799 $recipient[5]=Supreme Industrial Park, Unit F 25, Cnr. Heidelberg Road & Southern Klipriviersberg Road, Steeledale, Johannesburg $recipient[6]=18 $recipient[7]= $recipient[8]= $mailaddp[1] $recipient[0]=Pierre du Toit $recipient[1]=Test Supplier Two $recipient[2]=pierre@greywacke.co.za $recipient[3]=10000 $recipient[4]=27729154799 $recipient[5]=880 13th Avenue, Wonderboom South, Pretoria, 0084 $recipient[6]=19 $recipient[7]= $recipient[8]= notice the last two elements of the split arrays are dropped. could this be because of a stack overflow or something? i am not receiving any errors, yet there should be? the database field names are correct (text_GoogleMapsURL and text_VTigerData). could anyone please give me some clarity! i can't seem to find anything on the web with regard to multidimentional arrays vs split strings.
  2. thanks justsomeguy,for steering me back on track :)i noticed yesterday that the problem was something to do with the WHERE clause, but i was a bit flabbergasted to say the least... :)so let me restart and run over the requirements... so basically i will need the two nested IFNULL()'s, and 3 subqueries... here is what i came up with:SELECT IFNULL( ( SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = ( SELECT (1 + 12_prospectmessages.smallint_ProspectMessageCount) AS newid FROM 12_prospectmessages, 13_prospectleadsent WHERE 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_SupplierID = 20 AND 12_prospectmessages.bigint_ServiceID = 1 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount DESC LIMIT 1 ) ) , ( SELECT IFNULL( ( SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE NOT EXISTS ( SELECT * FROM 13_prospectleadsent, 12_prospectmessages WHERE 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_SupplierID = 20 AND 12_prospectmessages.bigint_ServiceID = 1 ) AND 12_prospectmessages.smallint_ProspectMessageCount = 1 AND 12_prospectmessages.bigint_ServiceID = 1 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount ASC LIMIT 1 ) , ( SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = 99 AND 12_prospectmessages.bigint_ServiceID = 1 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount ASC LIMIT 1 ) ) )) AS bigint_MessageID; i tested this on PMA in all 3 instances: an existing prospecting supplier, a new prospecting supplier, and a prospecting supplier that has received all the messages before.this issue has been resolved!!!
  3. awesome!!! :)i've started compiling the following statement, and tested it in PMA to implement the requirements stated above: SELECT IFNULL( ( SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = ( SELECT (1 + 12_prospectmessages.smallint_ProspectMessageCount) AS newid FROM 12_prospectmessages, 13_prospectleadsent WHERE 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_SupplierID = 17 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount DESC LIMIT 1 ) ) , ( SELECT IFNULL( ( SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = 99 AND 12_prospectmessages.bigint_ServiceID = 1 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount ASC LIMIT 1 ) , ( SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = 1 AND 12_prospectmessages.bigint_ServiceID = 1 AND WHERE NOT EXISTS (SELECT * FROM 13_prospectleadsent WHERE 13_prospectleadsent.bigint_SupplierID = 17) ORDER BY 12_prospectmessages.smallint_ProspectMessageCount ASC LIMIT 1 ) ) )); something is not working with the WHERE NOT EXISTS clause. the error i receive is the following: all the brackets are closing and correct (i tested this with Notepad++, which has syntax highlighting and tabbing/bracket binding aswell. i am struggling to see this forest for the trees...
  4. okay here is revision 3 of the sql code... SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = ( SELECT (1 + 12_prospectmessages.smallint_ProspectMessageCount) AS newid FROM 12_prospectmessages, 13_prospectleadsent WHERE 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_SupplierID = 17 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount DESC LIMIT 1) this works for selecting the next one for smallint_ProspectMessageCount up to 4, but 5 or 99 should return the id of smallint_ProspectMessageCount = 99.how do i implement an IF ELSE into a mysql statement? i believe it should be possible... another IF ELSE might be required should 1 + NULL != 1. logic dictates it should however... back to research when i wake up
  5. okay after some thinking, i've come up with the following sql statement... the only question is how would i be able to include an if statement in the select subquery? SELECT 12_prospectmessages.bigint_MessageID FROM 12_prospectmessages WHERE 12_prospectmessages.smallint_ProspectMessageCount = (SELECT (1 + 12_prospectmessages.smallint_ProspectMessageCount) AS newid FROM 13_prospectleadsent WHERE 13_prospectleadsent.bigint_SupplierID = 5 ORDER BY 13_prospectleadsent.smallint_ProspectMessageCount DESC LIMIT 1) this query unfortunately returns a blank recordset in PMA... how would i be able to do such a selection? if smallint_ProspectMessageCount < 99 and exists give the relevant bigint_MessageID, else give smallint_ProspectMessageCount = 99's bigint_MessageID...please help here, i seem to be totally stumped!
  6. in the smallint_ProspectMessageCount field, on the 12_prospectmessages table, there are messages with number 1-5 and 99 for if the last message sent was smallint_ProspectMessageCount != 99 and existing.
  7. hi there,sitting with a bit of a mental block atm, i need to select the message id (by next message number) from table a where table b contains records of messages sent to suppliers.how would i go about this?something like the following perhaps? SELECT 12_prospectmessages.bigint_MessageID, 12_prospectmessages.smallint_ProspectMessageCount FROM 13_prospectleadsent, 12_prospectmessages WHERE 13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 13_prospectleadsent.bigint_SupplierID = 5 ORDER BY 12_prospectmessages.smallint_ProspectMessageCount DESC if no records are found in table b then the first message number's id should be selected. how would i go about this sql select statement? something tells me that the above attempt will not work.
  8. okay. a php function already exists: utf8_decode, and this was the solution to my problem.this issue has now been RESOLVED.
  9. okay i seem to have discovered a solution, SELECT 6_serviceleads.bigint_LeadID, 6_serviceleads.text_Consumer, 6_serviceleads.text_LeadSubject, 6_serviceleads.text_LeadAttributes, 6_serviceleads.text_LeadMessage, 6_serviceleads.bigint_ServiceID, 6_serviceleads.bigint_SupplierID, 6_serviceleads.bigint_RegionID, 6_serviceleads.tinyint_LeadSent, 6_serviceleads.timestamp_LeadCreated, 2_servicescatalogue.bigint_ServiceID, 2_servicescatalogue.text_ServiceDescription, 2_servicescatalogue.bigint_CostPerLead, 5_suppliers.bigint_SupplierID, 5_suppliers.text_SupplierName, 5_suppliers.text_SupplierW3, 5_suppliers.text_ContactFirstName, 5_suppliers.text_ContactSurname, 5_suppliers.text_ContactPosition, 5_suppliers.`text_ContactE-mail`, 5_suppliers.bigint_ContactTel, 5_suppliers.bigint_CurrentBalance, 1_regions.bigint_RegionID, 1_regions.text_RegionDescription FROM 6_serviceleads LEFT JOIN 2_servicescatalogue ON (2_servicescatalogue.bigint_ServiceID = 6_serviceleads.bigint_ServiceID) LEFT JOIN 5_suppliers ON (5_suppliers.bigint_SupplierID = 6_serviceleads.bigint_SupplierID) LEFT JOIN 1_regions ON (1_regions.bigint_RegionID = 6_serviceleads.bigint_RegionID) WHERE 6_serviceleads.bigint_ServiceID = 1 ORDER BY 6_serviceleads.timestamp_LeadCreated DESC;
  10. if i try doing a normal select from four tables, the records with supplier id 0 get omitted, they only show if i do a LEFT JOIN - but all the other records then return null values despite there being records.is there any way to select data from 4 tables, if one of the tables does not have matching records in it? (null values or complete omittal of the supplier table).
  11. hi there,i have a SELECT JOIN statement and i need to select leads even if supplier id = 0, the region will be available. yet if i use LEFT JOIN i keep getting NULL as the joined values, no matter from which table. is there a way to circuimvent this?here is the code: SELECT 6_serviceleads.bigint_LeadID, 6_serviceleads.text_Consumer, 6_serviceleads.text_LeadSubject, 6_serviceleads.text_LeadAttributes, 6_serviceleads.text_LeadMessage, 6_serviceleads.bigint_ServiceID, 6_serviceleads.bigint_SupplierID, 6_serviceleads.bigint_RegionID, 6_serviceleads.tinyint_LeadSent, 6_serviceleads.timestamp_LeadCreated, 2_servicescatalogue.bigint_ServiceID, 2_servicescatalogue.text_ServiceDescription, 2_servicescatalogue.bigint_CostPerLead, 5_suppliers.bigint_SupplierID, 5_suppliers.text_SupplierName, 5_suppliers.text_SupplierW3, 5_suppliers.text_ContactFirstName, 5_suppliers.text_ContactSurname, 5_suppliers.text_ContactPosition, 5_suppliers.`text_ContactE-mail`, 5_suppliers.bigint_ContactTel, 5_suppliers.bigint_CurrentBalance, 1_regions.bigint_RegionID, 1_regions.text_RegionDescription FROM 6_serviceleads LEFT JOIN ( 2_servicescatalogue, 5_suppliers, 1_regions) ON ( 2_servicescatalogue.bigint_ServiceID = 6_serviceleads.bigint_ServiceID AND 5_suppliers.bigint_SupplierID = 6_serviceleads.bigint_SupplierID AND 1_regions.bigint_RegionID = 6_serviceleads.bigint_RegionID) WHERE 6_serviceleads.bigint_ServiceID = 1 ORDER BY 6_serviceleads.timestamp_LeadCreated DESC
  12. Basically, what I need to know is, how would I use (and possibly recreate), effectively - a PHP 5 version of the JavaScript decodeURIComponent() function?All the results that I get from a web search on "PHP decodeURIComponent", both on Yahoo and Google, return with unhelpful information.
  13. hi again,i've been asked to add a live form validation, disabling and enabling the budget dropdown's options as the user selects the form fields. i don't allow the form to submit if the user chose an option that is later disabled due to the requirements specified. here is what was asked for: now i did the following script at first, but i am thinking now, that it would be better to do nested switch case statements.function ValidatePrice(form) { var req = form.canopy_req.options[form.canopy_req.selectedIndex].value.toLowerCase(); var style = form.canopy_style.options[form.canopy_style.selectedIndex].value.toLowerCase(); var make = form.vehicle_make_model.options[form.vehicle_make_model.selectedIndex].value.toLowerCase(); var price = form.budget; for (var i = 0; i < price.options.length; i++) { var pval = price.options[i].value; // enable first element if (pval.indexOf("select")>-1) { price.options[i].disabled = false; // new white } else if (req.indexOf("new")>-1&&req.indexOf("white")>-1&&style.indexOf("spacesaver")>-1&&(pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("white")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("lwb")>-1&&(pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("white")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("cab")>-1&&(pval.indexOf("R7,500")==0||pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("white")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("kia")>-1&&(pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("white")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("hyundai")>-1&&(pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("white")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("hyundai")==-1&&make.indexOf("kia")==-1&&make.indexOf("cab")==-1&&make.indexOf("lwb")==-1&&(pval.indexOf("R5,000")==0||pval.indexOf("R7,500")==0||pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; // new colour } else if (req.indexOf("new")>-1&&req.indexOf("colour")>-1&&style.indexOf("spacesaver")>-1&&(pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("colour")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("lwb")>-1&&(pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("colour")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("cab")>-1&&(pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("colour")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("kia")>-1&&(pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("colour")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("hyundai")>-1&&(pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else if (req.indexOf("new")>-1&&req.indexOf("colour")>-1&&style.indexOf("spacesaver")==-1&&make.indexOf("lwb")==-1&&make.indexOf("cab")==-1&&make.indexOf("kia")==-1&&make.indexOf("hyundai")==-1&&(pval.indexOf("R7,500")==0||pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; // pre-owned white } else if (req.indexOf("pre-owned")>-1&&req.indexOf("white")>-1) { price.options[i].disabled = false; // pre-owned colour } else if (req.indexOf("pre-owned")>-1&&req.indexOf("colour")>-1&&(pval.indexOf("R4,000")==0||pval.indexOf("R5,000")==0||pval.indexOf("R7,500")==0||pval.indexOf("R10,000")==0||pval.indexOf("R12,500")==0)) { price.options[i].disabled = false; } else { price.options[i].disabled = true; } }} perhaps it would be better to use a combination of select cases with an if statement in between...just need some help clearing the vapour from a hot day under a galvanised iron roof.even nudges in the right direction would be greatly appreciated.it runs the ValidatePrice function on the document onload, canopy_req onchange, canopy_style onchange and vehicle_make_model onchange events.at the moment i am just wondering if there is another way to skin this cat that might be better practise. it's parsing the individual options and checking to see wether they should be enabled or not.the form can be viewed on the production site http://www.quoteme.za.net/canopy/, please do NOT submit dummy leads, though.
  14. ps: if i don't encode it and a string value contains an &, it breaks the post data. this is ajax, not a regular form i am afraid...pps: i gather it could be set in the post headers, but what would this be? *googles on this solong*...the solution i came up with should actually be on the javascript forum, but i have it onto this related topic. all the sites said adapt the backend, and i found one which had the option of adjusting the http_request object's character set, as well as the actual form's accept-charset="UTF-8". these are now both utf-8, but i still get Riëtte instead of Riëtte when sending encodeURIComponents over to the PHP handlers, to enter into the database. the function i have is to attempt to attempt performing a decodeURIComponent, in PHP.the returned xml document's encoding is also UTF-8. i need to know how the ###### can i "untaint" the strings as they are received server side. the javascript encodeURIComponent function messes some of the characters up.no more errors on encountering utf-8 characters anymore, but how to translate encodeURIComponent to the actual characters in PHP?
  15. okay, lets say it is the "form" that needs encoding. where would i do this here? the returned xmlresponse is already utf-8. 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) { alert('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.setCharacterEncoding("UTF-8"); 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++;}
  16. its being submitted via ajax post request, hence the encodeURIComponent to validate the request. my problem is how its received at the php ajax handler...
  17. oh i might also mention that the php functions meant to decode the URIencoding, such as urldecode, do not work here. i keep getting the ë replaced with ë through the encodeURIComponent function...
  18. ps: the character set used in mysql is utf8_unicode_ci, and the form these strings are parsed from are charset=utf-8. what is wrong that this php function which reportedly converts encodeURIComponent() tainted strings to UTF-8, does not do so? (skips over replacing the ë tainted as ë for instance, with ë again.)
  19. hi there,i believe i might have discovered what should be a simple solution to the jumbled characters i get as result of the encodeURIComponent javascript function, i need to decode this in php5.2.9.the only problem is - this does not convert to utf8 if ë was entered in the string... function UTF8URLDecode($value){ if (is_array($value)) { foreach ($value as $key => $val) { $value[$key] = UTF8URLDecode($val); } } else { $value = preg_replace('/%([0-9a-f]{2})/ie', 'chr(hexdec($1))', (string) $value); } return $value;} this code was adapted from http://weierophinney.net/matthew/archives/...ent-values.html.if i am getting problems with the first umlaud character i am testing this with, i assume the other UTF-8 unique characters will also be ignored.i've tried understanding regular expressions after 10 years, but i can't seem to find a logical explanation of regular expressions, either for javascript or php.could someone please help here!
  20. nevermind, this issue has been resolved. the problem was an  (a unicode character) in the string.
  21. hi there,a user attempted to insert a / (forwardslash character) into the database, again this screwed up the XML generated.how can i use a / character inside an xml attribute value? there doesn't seem to be an html entity for it...
  22. this issue has been resolved by adding a function in the form handler to convert the messed up characters to the originally input ones. function rep_lrdquotes($string) { return str_replace("â€","”",str_replace("“","“",$string));} thanks for all the attempted help!
  23. this issue has been resolved by adding a function in the form handler to convert the messed up characters to the originally input ones. function rep_lrdquotes($string) { return str_replace("â€","”",str_replace("“","“",$string));} thanks for all the attempted help!
  24. i tried that, but it replaces them with ? *sighs*unless you meant the utf8_decode as a javascript function, and not in the php AJAX handler where i implemented it...
×
×
  • Create New...