PHP - Complex Soapclient With Multiple Namespaces
Hi,
Well, I'm having this
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'GetSomething'. End element 'Body' from namespace 'http://schemas.xmlso.../soap/envelope/' expected. Found element 'param1' from namespace ''.
The soapclient request itself is something with multiple namespaces, like :
<aaa xmlns="namespace1">
<bbb xmlns="namespace2" xmlns:i="http://www.w3.org/20...hema-instance"> <requestparams>xxxxx</requestparams> </bbb> </aaa> So far I think this may got to do with multiple namespaces, so I've been trying to figure out how to deal with this for hours to no avail. Anyone can shed a light into this problem ? Thanks in advance, Similar TutorialsI need some help with the query for a form that selects values across multiple columns, and allow users to select multiple values in several columns. http://brinsterinc.com/tpa/tpasearch.php I assume you build the where clause for the sql by determining if there is an option value has been selected in the single-value select boxes. But how do I handle the multi-select list boxes? I'm desperate for help! Need to get somewhere with this over the weekend! TIA! Any charitable soul who can help me? I've been having this problem for days and I can't solve it. I would be forever grateful if anyone could help I already checked in phpinfo ()and the class soap client is enabled
the request that I 'm making is on another domain with port 81 (this domain has my ip on the withlisted) and on my domain I use security certificate. Is it around? anyway wsdl is he
$client = new SoapClient('https://dekrainspecoes.pt/acp/PROD_CustomUI_ACP_Member_Validation_WS.WSDL'); if (!empty($result->QueryByNumCartao_Output->Cartao_Ativo)) { echo 'The userId : '.$result->QueryByNumCartao_Output ->Pessoa_ID; } $JSON = json_encode($result); Hey Guys. I am new to using namespaces. I am trying to use it on the code below but it keeps giving me an error message saying Class 'lesson_one\Lecture' not found
I am not sure what I am doing wrong here... I have provided an example below. I know there is a duplicate conditional statement. But I am just working with this code to test out the namespace.
Any help would be really appreciated!
namespace lesson_one; abstract class Lesson { protected $duration; const FIXED = 1; const TIMED = 2; private $costtype; function __construct($duration, $costtype=1) { $this->duration = $duration; $this->costtype = $costtype; } function cost(){ switch($this->costtype) { case self::TIMED: return (5* $this->duration); break; case self::FIXED: return 30; break; default: $this->costtype = self::FIXED; return 30; } } function chargeType() { switch($this->costtype) { case SELF::TIMED: return "hourly rate"; break; case self::FIXED : return "fixed rate"; break; default: $this->costtype = self::FIXED; return "fixed rate"; } } } class Lecture extends Lesson { } class Seminar extends Lesson { } //echo Lesson::FIXED; $lecture = new \lesson_one\Lecture("5", Lesson1::FIXED); echo $lecture->cost(). "<br>"; echo $lecture->chargeType(). "<br>"; Hey, I've got a REALLY complicated issue. I'll do my best to explain it. I have a 3rd party API (soap) that I'm trying to integrate, I'd like to use namespaces to keep their objects/classes separate from ours. In a nut shell what is happening is that I have a soap struct which maps down to a php object (Transaction) inside that object are more objects. as i build out the parameter array to pass to soapCall everything looks good. however the xml that gets generated by soapCall is missing the transaction value, the tag is their <transaction/> but no value. Now, I assumed this is due to namespacing ruining the automated object detection in the soap client. SO i did: $auth->transaction = new \soapVar($bank_trans, XSD_ANYTYPE, "Transaction" , "http://masked/Transactions"); this gets the value into the xml however now i get a really weird error soapFault: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://masked/Transactions:transaction. The InnerException message was 'Error in line 2 position 4965. Element 'http://masked/Transactions:transaction' contains data of the 'http://masked/Transactions:Transaction' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Transaction' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details. in /home/jvieira/dev/www/trunk/include/CWS/CWSBankcard.php on line 1001 Call Stack #TimeMemoryFunctionLocation 10.0061930576{main}( )../TransactionManagement.php:0 20.00822682296CWS\CWSClient->authorize( )../TransactionManagement.php:156 30.00832695680CWS\CWSBankcard->Authorize( )../CWSClient.php:418 40.00832696736SoapClient->__soapCall( )../CWSBankcard.php:1001 ) ) any ideas? Thanks, Joe when trying to call
get_class($this)it will return the namespace of my class Application\Models\User_Model But what im really after is just User_Model... is there a way of actually getting the class name and not the namespace itself? thought i'd ask before making a class for that...thank you Does the concept of a "Namespace" exist in PHP? If so, how do you use them? This is a snippet from ASP.NET that made me ask this question... Quote <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> TomTees Hey, 'all. I think I'm just tired because I can't see the issue here, but I'm trying to run a SOAP 1.2 call to a legit endpoint using a legit function call and getting nothing but a 'Could not connect to host' message with a fault code of 'HTTP'. Here's some code: class Testing{ private $_user = "username"; private $_pass = "password"; private $_system = 1; private $_uri = "http://legit.com/endpoint/"; private $_location = "givenlocation.asmx"; private $_soapClient; public function __construct(){ $this->_soapClient = new SoapClient(null, [ 'location' => "{$this->_uri}{$this->_location}", 'uri' => $this->_uri, 'soap_version' => SOAP_1_2, 'exceptions' => true, 'trace' => true, ]); } public function makeCall(){ try{ $data = $this->_soapClient->__soapCall('functionCall', [ 'username' => $this->_user, 'password' => $this->_pass, ]); }catch(SoapFault $e){ die("<pre>".var_export($e, true)."</pre>"); } } } $testSoap = new Testing(); $testSoap->makeCall(); I'll happily take a "Let me Google that for you" result link if it's that simple, but I'm just not seeing the problem. Anybody? As always, help is greatly appreciated.
Forgot to mention - I don't get an error on instantiation of the SoapClient() object, just the __soapCall() call. Edited June 18, 2019 by maxxdHi y'all. I've been looking at this for two days now and my head is starting to hurt from it.
I'm trying to integrate with an existing web service for client log-in and having trouble getting it done and Google is being very little help at this point. Here's the code, annotated where necessary:
namespace myNamespace; MyClass{ private $_apiLoginAddr = 'http://xxx.xxx.xxx.xxx:xxxx/ServiceAddress/Login.asmx?wsdl'; public function logIn($email,$id){ /* // these work... $testClient = new \SoapClient('http://www.webservicex.com/CurrencyConvertor.asmx?wsdl',array('trace'=>1,'exceptions'=>1)); $resp = $testClient->ConversionRate(array('FromCurrency'=>'USD','ToCurrency'=>'CAD')); print($resp->ConversionRateResult); $testClientAWS = new \SoapClient('http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl',array('trace'=>1,'exceptions'=>1)); $resp = $testClientAWS->ItemLookup(array('ItemID'=>'1430260319')); var_dump($resp); $testClientP = new \SoapClient('https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl',array('trace'=>1,'execptions'=>1)); print_r($testClientP->__getFunctions()); die(); */ // turning off caching because apparently it's sometimes an issue... ini_set('soap.wsdl_cache_enbled','0'); ini_set('soap.wsdl_cache_ttl','0'); // this doesn't work even a little bit... try{ $creds = array( 'trace' => 1, 'exceptions' => 1, 'cache_wsdl' => 'WSDL_CACHE_NONE', 'soap_version' => SOAP_1_1, ); $client = new \SoapClient($this->_apiLoginAddr,$creds); $results = $client->WebsiteLogin(array('_Password'=>$id,'_UserName'=>$email)); var_dump($client->__getLastRequest()); print('break'); var_dump($client->__getLastResponse()); }catch(\SoapFault $e){ print('Exception thrown!'); var_dump($e); die(); } print('Succesfully completed call!'); var_dump($results); die(); } }Using this code, the browser churns for about a minute before I get the error "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xxx.xxx.xxx.x...ceAddress/Login.asmx' : failed to load external entity "http://xxx.xxx.xxx.x...ess/Login.asmx", with or without the call to WebsiteLogin(). Now, I've also tried a non-wsdl version where I replaced the credentials array and SoapClient instantiation with the following: try{ $creds = array( 'trace' => 1, 'exceptions' => 1, 'cache_wsdl' => 'WSDL_CACHE_NONE', 'location' => $this->_apiLoginAddr, 'uri' => 'http://tempuri.org', 'soap_version' => SOAP_1_1, ); $client = new \SoapClient(null,$creds); $results = $client->WebsiteLogin(array('_Password'=>$id,'_UserName'=>$email)); /* see previous code block */Using this approach, my browser again churns for about a minute before I get the error "Could not connect to host". If I don't actually try to log in using the service's WebsiteLogin() function, SoapClient doesn't throw an error on this one and reports a successfully completed call. Which does me no good at all, because my users can't log in if I don't call the WebsiteLogin() function. I can visit the end-point directly in my browser and it's definitely there and active, and SoapUI has no problem at all with the request or the response. I've tried uncommenting the open_ssl.dll in my php.ini, turning the wsdl caching options off in the php.ini directly, and pretty much everything short of ritual sacrifice to no avail. My log in form is sending the credentials via AJAX to the logIn() method above, and all this is happening in a WordPress site. However, as the webservicex, webservices.amazon.com, and pilot.prove-uru.co.uk soap calls all complete successfully, I don't think that's an issue. I've spoken with the maintainer of the service gateway and he swears we're not blacklisted through the firewall, but nothing is working. Anybody come across anything similar? Or have better Google skills that can actually find an applicable answer? Or have any ideas at all? 'Cause I'm at a loss...
I have to be doing something wrong here, but so far Googling hasn't helped. Take a look he
https://demo.envrin.com/api/classes/apex.app.msg.emailer.html#method_send
The doc-block is correct, or at least as far as I can tell it is, character-by-character. I'm blind though, but have tried different combinations of things like "String" instead of "string" or "@Param" instead of "@param". Made sure the ends of the @param lines ende din a period, and that seemed to help a little.
Nonetheless, why does it keep adding the namespace to everything in front of "string" like that? Any why are the paramaters section all screwed up?
Any help would be appreciated. Thanks!
I'm not entirely sure what is wrong with me, but I'm having a super difficult time understanding namespaces.
I have 2 primary classes
# Resides within class.DataTypeBase.php namespace DTB\Base; class DataTypeBase { protected $name = ''; protected function getName() { return $this->name; } protected function setName($name) { $this->name = $name; } } # Resides within class.DataType.php namespace DTB; class DataType extends DataTypeBase { public function process_data(){ .... } }I then have a third file that contains approximately 9 different classes that further extend DataType # Resides within class.DataTypes.php namespace DataTypes; class Silver extends DataType { public function differ($type) { .... } }The namespace system seems to work for class DataTypes, but with the class Silver I get an error message saying that the class DataType does not exist. From what I read online, and using the example above I figured the "extends DataType" may have to be "extends \DTB\DataType" but it results in the same error message. I'm not entirely sure what I need to do for this to work properly Hi everyone, I'm still kind of a noob when it comes to PHP although i am learning more when i can. I'm in the middle of creating an affiliate system in PHP/MySQL and as you'll be able to tell from looking at my code I'm no expert in it and no doubt what I've created can be done in a more efficient way. This is where i need your help, for 2 different reasons, one to guide/help me re-create my script the way you would do so. The second thing i need help with is (EDIT: i think we'll concentrate on re-creating the script first of all). //BEGIN GETTING BRAND NAMES $connection = mysqli_connect( "$connectip", "$swiftuser", "$swiftpass", "$swiftdb" )or die( "Error " . mysqli_error( $connection ) ); $sql = "SELECT Name, ProgramID FROM programs WHERE Status='1'"; $result = mysqli_query( $connection, $sql )or die( "Error in Selecting " . mysqli_error( $connection ) ); if ( $result->num_rows > 0 ) { while ( $row = $result->fetch_assoc() ) { $ProgramID = $row[ "ProgramID" ]; //BEGIN GETTING CLICKS THAT MONTH FOR THE BRAND $startmonth = date( 'Y-m-d', strtotime( 'first day of this month' ) ); $endmonth = date( 'Y-m-d', strtotime( 'last day of this month' ) ); $todaysdate = date( 'Y-m-d' ); $sqlclicks = "SELECT COUNT(*) AS 'TotalMonth' FROM `clicks` WHERE AffID = '$AffID' AND ProgramID = '$ProgramID' AND DATE(Timestamp) BETWEEN '$startmonth' AND '$endmonth' "; //echo $sqlclicks; $resultclicks = mysqli_query( $connection, $sqlclicks )or die( "Error in Selecting " . mysqli_error( $connection ) ); if ( $resultclicks->num_rows > 0 ) { while ( $rowclicks = $resultclicks->fetch_assoc() ) { $clicks = $rowclicks[ "TotalMonth" ]; } } else { $clicks = "0"; } //END GETTING CLICKS THAT MONTH FOR THE BRAND //BEGIN GETTING REGISTRATIONS THAT MONTH FOR THE BRAND $sqlreg = "SELECT COUNT(*) AS 'TotalReg' FROM `players` WHERE AffID = '$AffID' AND ProgramID = '$ProgramID' AND DATE(SignupDate) BETWEEN '$startmonth' AND '$endmonth' "; //echo $sqlclicks; $resultreg = mysqli_query( $connection, $sqlreg )or die( "Error in Selecting " . mysqli_error( $connection ) ); if ( $resultreg->num_rows > 0 ) { while ( $rowreg = $resultreg->fetch_assoc() ) { $reg = $rowreg[ "TotalReg" ]; } } else { $reg = "0"; } //END GETTING REGISTRATIONS THAT MONTH FOR THE BRAND //BEGIN GETTING FTDs THAT MONTH FOR THE BRAND $sqlftd = "SELECT COUNT(*) AS 'TotalFTDs' FROM `players` WHERE AffID = '$AffID' AND ProgramID = '$ProgramID' AND FTDmatched ='1' AND DATE(FTDmatchedDate) BETWEEN '$startmonth' AND '$endmonth' "; //echo $sqlftd; $resultftd = mysqli_query( $connection, $sqlftd )or die( "Error in Selecting " . mysqli_error( $connection ) ); if ( $resultftd->num_rows > 0 ) { while ( $rowftd = $resultftd->fetch_assoc() ) { $ftds = $rowftd[ "TotalFTDs" ]; } } else { $ftds = "0"; } //END GETTING FTDs THAT MONTH FOR THE BRAND //BEGIN CPA COMMISSION THAT MONTH FOR THE BRAND $sqldeal = "SELECT DealID AS `DealID`, SUM(CASE WHEN FTDmatched = '1' THEN 1 ELSE 0 END) AS `TotalFTDs` FROM players WHERE AffID = '$AffID' AND ProgramID = '$ProgramID' AND `FTDmatchedDate` BETWEEN '$startmonth' AND '$endmonth' GROUP BY DealID"; //echo $sqldeal; $resultdeal = mysqli_query( $connection, $sqldeal )or die( "Error in Selecting " . mysqli_error( $connection ) ); $dealid = array(); $dealftds = array(); $i = 0; if ( $resultdeal->num_rows > 0 ) { while ( $rowdeal = $resultdeal->fetch_assoc() ) { $dealid[ $i ] = $rowdeal[ "DealID" ]; $dealftds[ $i ] = $rowdeal[ "TotalFTDs" ]; $i = $i + 1; } } else { $commissionftd = "0.00"; } $totaldeals = count( $dealid ); //echo "<br>"; //echo "Total Deals for Affilaite is: " . $totaldeals; $sqlpayout = array(); $totalcpa = array(); for ( $tt = 0; $tt < count( $dealid ); $tt++ ) { $sqlamount = "SELECT CPA AS `CPAAmount` FROM affDeals WHERE AffID = '$AffID' AND `affDealID` = '$dealid[$tt]' AND `Type` = 'CPA' AND `StartDate` <= '$todaysdate' AND `EndDate` >= '$todaysdate' OR AffID = '$AffID' AND `affDealID` = '$dealid[$tt]' AND `Type` = 'Hybrid' AND `StartDate` <= '$todaysdate' AND `EndDate` >= '$todaysdate'"; //echo "<br>" . $sqlamount . "<br>"; $resultamount = mysqli_query( $connection, $sqlamount )or die( "Error in Selecting " . mysqli_error( $connection ) ); if ( $resultamount->num_rows > 0 ) { while ( $rowamount = $resultamount->fetch_assoc() ) { $sqlpayout[ $tt ] = $rowamount[ "CPAAmount" ]; $totalcpa[ $tt ] = $sqlpayout[ $tt ] * $dealftds[ $tt ]; } } else { $sqlpayout[ $tt ] = "0.00"; } } //END CPA COMMISSION THAT MONTH FOR THE BRAND $totalcommission = array_sum( $totalcpa ); echo '<tr> <td>' . $row[ "Name" ] . '</td> <td>' . $clicks . '</td> <td>' . $reg . '</td> <td>' . $ftds . '</td> <td>£' . $totalcommission . '</td> </tr>'; } } else { echo "0 results"; } //END GETTING BRAND NAMES ?> I've also attached the SQL tables, the table Affiliates is just the structure so you will need to add a record in there. All other tables have data in them for you to work with. EDIT: since i cant upload SQL files on here you can download them he https://ufile.io/gnoqf I find it a lot easier for me to learn PHP by trying to create stuff myself, then if i need help i do some research on how to achieve what I'm trying to code and if i fail i keep trying to doing more research until it works. I also ask other PHP developers for advice and help and if they provide me with examples then again that helps me learn a lot better and quicker as i can see first hand how its supposed to look and how it works. I apologise for my messy coding but like i said I'm still learning PHP, if anyone could help me re-create my script more efficiently I'd very much appreciate that. Maybe I've done too much code and certain MySQL queries can be done in just 1 MySQL Query instead of multiple ones, i don't know and that's why I'm here asking for help/advice to help me learn more. Anyway thank you in advance and if you'd like to know any information please let me know. Well, as i said in my previous post, im pretty new into php, mysql, i was searching into how to make queries but i can't find where to learn doing real complex ones. This is how it goes, -i've got an array full of id's -inside my table i wan't to get all the values where folder_id == to any id inside my array(i guess a loop would do this) -and i wan't to get only the first 20 values of the columns (folder_id and photo) for every folder_id any suggestions? thanks Hi,
Is it possible to create an web-page,form,that would accept specific input and generate Xojo or Php for this could be used, below is the sample XML file and Data Format.
<?xml version="1.0" encoding="UTF-8" ?>
If Yes, then how to write the desired PHP code to solve this problem?
Thanks This is the array Array (2) ( | ['0'] => Array (6) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(3) 100 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | | ['amt'] = Integer(2) 30 | ) | ['1'] => Array (6) | ( | | ['name'] = String(8) "Champion" | | ['hp'] = Integer(3) 150 | | ['atk'] = Integer(1) 8 | | ['def'] = Integer(1) 6 | | ['rng'] = Integer(1) 5 | | ['amt'] = Integer(2) 10 | ) ) I have an attack value ( say 300 ). I want to take this value and minus the first key amount $array[0]['amt']. If that value then comes to 0 I then want to skip to the next array key and do the same $array[1]['amt'] until the attack value runs out or every array keys amount is equal to 0. Any ideas? Greetings - So I have an issue with my form right now which can be found he http://youawfulme.com/Form.html If you look, you will see two expanding columns under Providers and References. The HTML code for them to expand looks like this: Quote <span class="duplicateSpan"><a id="tfa_0583059728034-wfDL" class="duplicateLink" href="#">Next Provider</a></span> and the PHP code that handles their database storage looks like this: Quote // Insert Providers.. if(count($_POST['tfa_FirstName1']) > 1) { for($i = 0; $i < count($_POST['tfa_FirstName1']); $i++) { $tmpsql = "INSERT INTO tmpProviders (tmpId,FirstName,LastName,LicenseType,PrimarySpecialty,SecondarySpecialty,NYStateLicenseNum,DEANumber,NPINumber,EmailAddress,DaysPerWeek,PrimaryCareProv) VALUES ($oldid,'" . $_POST['tfa_FirstName1'][$i] . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_LastName1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_LicenseType1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_PrimarySpecialty1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_SecondarySpecial'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NYStateLicenseNu1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DEANumber1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NPINumber1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_EmailAddress1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DaysPerWeek1'][$i]) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d+/","\\1",$_POST['tfa_Ifthisindividual'][$i]) . "');"; mysql_query($tmpsql); } } else { $tmpsql = "INSERT INTO tmpProviders (tmpId,FirstName,LastName,LicenseType,PrimarySpecialty,SecondarySpecialty,NYStateLicenseNum,DEANumber,NPINumber,EmailAddress,DaysPerWeek,PrimaryCareProv) VALUES ($oldid,'" . $_POST['tfa_FirstName1'] . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_LastName1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_LicenseType1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_PrimarySpecialty1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_SecondarySpecial']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NYStateLicenseNu1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DEANumber1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NPINumber1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_EmailAddress1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DaysPerWeek1']) . "'"; $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d+/","\\1",$_POST['tfa_Ifthisindividual']) . "');"; mysql_query($tmpsql); } if(count($_POST['tfa_PracticeName']) > 1) { At this moment, when you fill out my form, all of the information saves to three separate tables. The Provider input goes into a temporary providers table, the Referrals to a temporary Referral , and the rest of the data to a temporary information table. Once the user submits the application, the temporary tables are cleared after having been moved to permanent tables (Still three tables) My goal is for all of these values to save to one table, whether it be from three separate temps to one final or one temp to one final. My programmer was having trouble figuring it out and kind of left me on my own.. I really need some help The Providers and Reference tables are done in such a way that if there are more than one entry, it will create a new row for each entry with a new ID number but the same "tempid" number, the latter matching the ID number in the main information table. Can I have it such that PHP will check to see if the tempIDs match, and if they do, move the information into new columns on the same row? So that way, instead of having say 3 different IDs with one temp ID for three different providers.. instead have that information all placed on one row, with one ID, and new columns? In my head, I figured I would expand my table 5x. If I have five columns now, I will have 25 after. For each "Provider Name", I will now have "Second Provider Name", "Third Provider" name, etc... If the user only adds one provider, these won't be used. If they had multiples, up to five, the info will be placed into these new columns. I just can't get this to work.. When I expand the column and inspect the element in HTML, it says, for example, Provider[1] and Provider[2] .. Incrementing in brackets for each addition. But if I try to, say Quote $SecondProviderName = $_POST['tfa_ProviderName[2]']; .. It simply doesn't work. Sorry for all this, I just need some help and so far you guys have been a great resource. Thank you Hey. I am not 100% with it at the moment, bit under the weather. (If you ask why I am working, your not a developer) Sob story aside (excuses really) Basically I have built a function to manipulate BB Code to HTM I wrote it, looked back at it and thought, my god this looks overly complex for this sort of thing. It works but just seems like a lot of wasted code. Please help me narrow this down public function BB2HTM($str){ /* Valid BB Code [b] / [/b] = STRONG [i] / [/i] = Italic [u] / [/u] = Underline [url=http://www.example.com]My Example[/url] = A Link [size=X]bla[/size] = Change font size where X is percentage of actual size, default options 50=>small, 100=>normal, 200->large [list]bla[/list] Handles Unordered Lists, with New Line being new list item [list=X]bla[/list] Handles Ordered List, where X is start number, again New Line is New List item */ /* First, we will do the basics, with a simple str_replace */ $str = nl2br($str); $arrBBCode = array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]'); $arrHTMCode = array('<strong>', '</strong>', '<i>', '</i>', '<u>', '</u>'); $str = str_replace($arrBBCode, $arrHTMCode, $str); // /* Now we want to handle a URL, open in new window */ $regexURLPattern = '#(\[url\=(.*))(\])(.*?)(\[/url\])#is'; preg_match_all($regexURLPattern, $str, $arrMatches); /* Loop through the results, build a valid HTM link and replace what we found with the correct format */ for($i = 0; $i < count($arrMatches[0]); $i++){ $strNewLink = '<a href="'.$arrMatches[2][$i].'" target="_blank">'.$arrMatches[4][$i].'</a>'; $str = str_replace($arrMatches[0][$i], $strNewLink, $str); } /* End Handle URL */ /* Now font size. User can maniplate the number on size so we want to check for this and limit, so someone dont put 1% and hide stuff or 10000% and break the website */ $regexSizePattarn = '#(\[size=)([0-9]*)(\])#'; preg_match_all($regexSizePattarn, $str, $arrMatches); /* Loop through the results, put a check on the number */ for($i=0; $i < count($arrMatches[0]); $i++){ if($arrMatches[2][$i] > 200){ $arrMatches[2][$i] = 200; }elseif($arrMatches[2][$i] < 100){ $arrMatches[2][$i] = 100; } /* Change it and close the tag, keep the str_replace with the opener for later editing / auditing */ $strFontTag = '<span style="font-size:'.$arrMatches[2][$i].'%">'; $str = str_replace($arrMatches[0][$i], $strFontTag, $str); } $str = str_replace('[/size]', '</span>', $str); /* End Handle Size */ /* Is it a list, What list, where to start */ $regexListPattern = '#(\[list)(=?)([0-9]*)?(\])(.*?)(\[/list\])#is'; preg_match_all($regexListPattern, $str, $arrMatches); /* Loop through our results */ for($i = 0; $i < count($arrMatches[0]); $i++){ $strLstItems = ''; /* Is it unordered or Ordered? Where do we start, 1 or 100 Add our closing tag here as well in variable, save doing this again*/ if($arrMatches[3][$i] != ''){ $strEndLst = '</ol>'; if($arrMatches[3][$i] > 1){ $strLstItems = '<ol start="'.$strLstItems[3][$i].'">'; }else{ $strLstItems = '<ol>'; } }else{ $strEndLst = '</ul>'; $strLstItems = '<ul>'; } /* We can split the New lines as we done nl2br() as the top, we split on br */ $arrListItems = split("<br />", $arrMatches[5][$i]); for($x = 0; $x < count($arrListItems); $x++){ /* We dont want empty items, where people double enter or something */ if($arrListItems[$x] != ''){ $strLstItems .= '<li>'.$arrListItems[$x].'</li>'; } } /* Close the item as set above and replace it in our main str */ $strLstItems .= $strEndLst; $str = str_replace($arrMatches[0][$i], $strLstItems, $str); } /* End Handle Lists */ return $str; } Hi; i would like to search for a regular expression to grab all printf occurences including the folowing senarios :
printf("something"); printf("something", variables); printf("something", variables, variables); printf("something);something", variables, variables);To simplify the third and fourth cases, the regex should start from printf(" and go intil it find ); with a white space after it. But i didn't realise how to do it. This trick should work also for the first and second case. Thanks Edited by Dareros, 26 September 2014 - 01:27 PM. I am so over my head right now that I don't even know where to begin asking for help?! (This is regarding a Form which ask 10 Questions and then captures and processed up to 10 Answers.) Originally, I had an answerArray where I captured and process all User Answers to Questions, and all was beautiful in the universe! Then after being 95% done, I got the - not so brilliant - idea of dynamically generating my Q&A Form with Questions being pulled from the question table (along with Answers from the answer table). Based on a recommendation from gizmola (??), I created a SECOND Question & Answer multidimensional array - thoughtsArray - which pulled together the Questions and Answers. This made sense, because it is easier to populate the Form when the dataset is coming all from one place. The problem is two-fold at this point... 1.) Is it a good or bad design to have answerArray to capture and process Form inputs, and then a thoughtsArray for display purposes?? 2.) How do I design a Form which allows both my multidimensional thoughtsArray and my one-dimesnional answerArray to plug into it, specifically the name attribute?? Here was my original array... foreach($_POST['answerArray'] as $q => $a){ // Copy data from POST to PHP array. $answerArray[$q] = trim($a); if (strlen($answerArray[$q]) > 1024){ // Invalid Answer. $errors[$q] = 'Answer cannot exceed 1024 characters.'; } }//End of VALIDATE FORM DATA And here is my new display array... // Populate PHP array with Questions & Answers. $x=1; while (mysqli_stmt_fetch($stmt7)){ $thoughtsArray[$x] = array('questionID' => $questionID, 'questionText' => $questionText, 'answerText' => $answerText); $x=$x+1; } Here is how my original - pre automation - Form looked... <!-- Question 1 --> <label for="question1">1.) Why did you decide to start your own business?</label> <textarea id="question1" name="answerArray[1]" cols="60" rows="2"><?php if (isset($answerArray[1])){echo htmlentities($answerArray[1], ENT_QUOTES);} ?></textarea> <?php if (!empty($errors[1])){ echo '<br /><span class="error">' . $errors[1] . '</span>'; } ?> And here is my new Form - which works for displaying, but is now broken for processing... <?php foreach($thoughtsArray as $questionNo => $qaArray){ // Build Question. echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . "\n"; // Build Answer. echo '<textarea id="question' . $questionNo . '" name="' . $qaArray["questionID"] . '" cols="60" rows="2">'; echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : ''); echo "</textarea>\n\n"; } ?> Hope that all makes sense?! Debbie Hi, currently I have a function searchFolder that simply takes in ONE directory which holds all the xml files I wish to store to db via function writeXMLtoDBviaDOM. I want to make it more robust(realistic) to be able to also search complex directories (so the main directory I pass as parameter to searchFolders) in turn holds sub-directory (which in turn holds further sub-directory) which finally holds all the xml files. here is code: Code: [Select] <?php $dir = "C:/dir/dir2/dir3/"; function searchFolders($dir) { $_filePath=""; $filePathsArray=array();//stores each file $xmlFiles = glob($dir . '*.xml'); if(is_dir($dir)) { // list files $xmlFiles = glob($dir . '*.xml'); //print each file name foreach($xmlFiles as $xmlFile) { print $xmlFile."<br />"; $filePathsArray[]=$xmlFile; } }//END BIG IF retreiving all files in dir param foreach($filePathsArray AS $curFile) { //set up db connection mysql_connect("localhost","root"); mysql_select_db("someDb"); $_filePath=$curFile; $dom=new DOMDocument(); $node=basename($_filePath);//$node is the file name only $dom->load($node); writeXMLtoDBViaDOM($dom->documentElement,$_filePath); }//END FOR-EACH LOOP for each XML file }//END FCN searchFolders VERSION 0 searchFolders($dir);//VERSION 0 ONLY searched 1 simple dir ?> Any help much appreciated! Hi I have an array from an sql query and i would like to eliminates all the duplicates, i have google search for an answer without success, any help would be aprecciated $result = $stmt->fetchAll(PDO::FETCH_ASSOC); $final = array(); $json = array(); if ($idCoord > 0 || $isDirecao > 0) { foreach ($result as $row) { $idAtividade = $row['idAtividade']; if (!isset($final[$idAtividade])) { $final[$idAtividade]['Escola'] = $row['Escola']; $final[$idAtividade]['Atividade'] = $row['Atividade']; $final[$idAtividade]['Periodo'] = $row['Periodo']; $final[$idAtividade]['Mes'] = $row['Mes']; $final[$idAtividade]['haveClasses'] = $row['haveClasses']; $final[$idAtividade]['DataPrevista'] = $row['DataPrevista']; $final[$idAtividade]['Destinatarios'] = $row['Destinatarios']; $final[$idAtividade]['Orcamento'] = $row['Orcamento']; $final[$idAtividade]['Organizador'] = $row['Organizador']; $final[$idAtividade]['Obs'] = $row['Obs']; $final[$idAtividade]['PdfAtividade'] = $row['PdfAtividade']; $final[$idAtividade]['Avaliacao'] = $row['Avaliacao']; $final[$idAtividade]['idProfessor'] = $row['idProfessor']; $final[$idAtividade]['PdfAvaliacao'] = $row['PdfAvaliacao']; $final[$idAtividade]['Validado'] = $row['Validado']; $final[$idAtividade]['Nome'] = array(); $final[$idAtividade]['Grupo'] = array(); $final[$idAtividade]['Departamento'] = array(); } $final[$idAtividade]['Nome'][] = $row['Nome']; $final[$idAtividade]['Grupo'][] = $row['Grupo']; $final[$idAtividade]['Departamento'][] = $row['Departamento']; } foreach ($final as $idVisita => $reservation) { $json[] = $reservation; } } echo json_encode($json); } And this is an example i'm receiving
So you can see that Grupo has 4 times the value "500" and Departamento has 4 times that string... How can avoid this and have only one value of each?
Thanks
|