Jump to content

pandyboy

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by pandyboy

  1. pandyboy

    CURL

    I too am having similar issues. All the tutorials and forum posts i read say to do as the OP suggests, however the $strPost (in the above example) simply gets posted as a string, which wouldn't be the end of the world except that the equals sign in <?xml version=\"1.0\" creates a post key and value of $_POST['<?xml version']="\"1.0\"....etc." I was under the impression that including the line curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); would either make curl convert the XML data into the appropriate POST values or at least leave the XML intact. There are no errors reported and if I pass a string such as name=bob&age=50&job=caretaker it all works fine.
  2. Apologies, yes you're right - after calling an SP then you need to free the result before running any other query. But that is still different to what I am doing! I am running one isolated SP. Not keen to post the exact SP code as it is quite complex and also I am bound by a non-disclosure agreement.
  3. I'm aware of the commands out of sync error, but that only happens if you run 2 SPs one after the other (or at least in my experience) and I can get over that with the usual way of freeing the result. In this case though I am running a single query which, even if it does return one recordset, should not as far as i can tell "trip itself up" - and if it did, surely it should be the same every time not random. Also, I was not getting any errors returned.
  4. There are no results. The SP merely runs some calculations and inserts various records. Nothing is returned.
  5. I think I have actually solved the problem now, but not sure why!! I used mysqli_multi_query instead of mysqli_query and it worked. Can anyone explain why this might be so when there is only one query?
  6. I have encountered an unsual problem when using mysqli to call a stored procedure from php. The procedure, which contains a CURSOR REPEAT is getting stuck in the middle. The loop will run one or two, maybe three times (it varies) and then apparently just stops. This, however, only occurs when I call the procedure from PHP using mysqli. If I call the procedure in Navicat, it works perfectly every time. The stored procedure code must be correct, as it works perfectly when run outside of PHP. No errors are returned when I run it from PHP. PHP code is simply as follows: $link = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysqli_error($link),E_USER_ERROR); $av_query="CALL available_quotes(123456)"; $av=mysqli_query($link,$av_query) or die(mysqli_error($link)); Any help would be appreciated. MySQL version 5.0.83 PHP version 5.2.9
  7. Solved it!! I created a function which calls itself until all elements which need to be removed have been... $allThings=array("dog","collar","lead","cat","mouse","trap"); $requiredThings=array("collar"=>"dog","lead"=>"collar","trap"=>"mouse"); $myThings=array("lead","trap","collar","cat"); function checkRequired ($allThings,$requiredThings,$myThings) { $count=count($myThings); foreach ($myThings as $myKey=>$myValue) { if ($requiredThings[$myValue]) { if (!in_array($requiredThings[$myValue],$myThings)) { echo $myValue." should be removed because there's no ".$requiredThings[$myValue]."<br>"; unset($myThings[$myKey]); } } } if($count!=count($myThings)) { $myThings=checkRequired($allThings,$requiredThings,$myThings); } return $myThings; } print_r(checkRequired($allThings,$requiredThings,$myThings));
  8. OK - I have written the code which does what I want if things are in logical order (i.e. dog comes before collar, before lead) as follows: <?php $allThings=array("dog","collar","lead","cat","mouse","trap"); $requiredThings=array("collar"=>"dog","lead"=>"collar","trap"=>"mouse"); $myThings=array("collar","lead","cat","trap"); foreach ($myThings as $myKey=>$myValue) { if ($requiredThings[$myValue]) { if (!in_array($requiredThings[$myValue],$myThings)) { echo $myValue." should be removed because there's no ".$requiredThings[$myValue]."<br>"; unset($myThings[$myKey]); } } } print_r($myThings); ?> This outputs: Which is correct - however if I jumble up the arrays into a random order as follows: $myThings=array("lead","trap","collar","cat"); I get But as you see "lead" is still there because it comes before "collar" in the array. I need a way to do this regardless of the order of the $myThings array.
  9. No - I don't want the difference between the two. I need a way of identifying the "required" items and then removing the items which don't have the items they require in the array. So because "collar" requires "dog" and "lead" requires "collar", if "dog" is not present, "collar" should be removed and then as a result so should "lead", even though "lead" does not directly require "dog"
  10. Hi I shall try and explain what I want to do.... I want an array of things - for example ("dog","collar","lead","cat","mouse","trap") "collar" requires "dog", "lead" requires "collar", "trap" requires "mouse" If I have a second array which is ("collar", "lead", "cat", "trap") I want to be able to check this array against the first and remove all elements that can't exist without another (so "collar" will be removed because there is no "dog" and "trap" will be removed because there is no "mouse") however, in this situation, because "collar" will be removed, "lead" should also then be removed. I can of course do this by looping through in order and rechecking the array each time, but if the array is not in a logical order then this method won't work reliably. Any suggestions how I could do this recursively? In brief: Main Array=("dog","collar","lead","cat","mouse","trap") 2nd Array=("collar","lead","cat","trap") Final array should be ("cat")
  11. It is in a class - I thought about globals, but as the variables are going to be so different each time the showPage function is called it wouldn't work. Sometimes, for example there'll be 2 or 3 MySQL recordsets, sometimes arrays, POST variables, GET variables etc etc. (The last 2 I can deal with of course).
  12. I am currently writing some code, in which I have a number of functions which display included files from a content folder, in a similar way to the following: public function myFunction() { $variable1 = "dog"; $array1=array("cat","pig","gnu"); $this->displayHeader(); ob_start(); include ($this->contentFolder.'page1.php'); echo ob_get_clean(); $this->displayFooter(); } In this example, page1.php contains references to the variable and array defined in the function. This works fine, but of course if I wanted to create a function to handle the displaying of the content, similar to the following:- public function showPage($filename) { $this->displayHeader(); ob_start(); include ($this->contentFolder.$filename); echo ob_get_clean(); $this->displayFooter(); } public function myFunction() { $variable1 = "dog"; $array1=array("cat","pig","gnu"); $this->showPage("page1.php"); } ..then the variables would of course not be passed to the showPage function. As the variables and arrays are going to be different each time the function is called, is there any way I can get this to work? I am just trying to streamline my code and also, ultimately, adapt the showPage function to do more such as checking if the file exists, present an alternative if not etc. etc. I'm open to suggestions.
  13. Thanks - that works beautifully. (By the way, B & I aren't deprecated. The difference between B & I and STRONG & EM is that the latter are used by screen readers to add strength or emphasis to words. As what I am doing is not ever intended for screen readers, but is purely visual, B & I are more appropriate)
  14. Thanks - much better! I really must get my head round regex!! If I wanted to add in 2 more replacements, for example replace [* & *] with <b> & </b> and [~ & ~] with <i> & </i>, could I do these with the same line of code, or would it require a subsequent preg_replace?
  15. OK, I think I am half way there now. I have adapted an example of preg_replace_callback from the PHP website, which gets me the value i need in 2 places, but I am having to use normal str_replace to finish the job, which seems a messy way to do it, as follows: $input = "[[#201001251351#]]Some text here[[end]] Something else in this bit [[#201001251353#]]Some different text here[[end]] And more different bits [[#201001251357#]]Some more here[[end]] Further different bits which may include other replaced things"; function parseTagsRecursive($input) { $regex = '#\[\[\#((?:[^[]|(?!/?\#]])|(?R))+)\#]]#'; if (is_array($input)) { $input = "<a href=\"javascript:;\" onclick=\"Show_Stuff('".$input[1]."');\">Vars</a> <div style=\"display:none;\" id=\"".$input[1]."\">"; } return preg_replace_callback($regex, 'parseTagsRecursive', $input); } $output = parseTagsRecursive($input); echo str_replace("[[end]]","</div>",$output); This gives the desired output, but can anyone improve on this?
  16. Hi - I have (for example) the following in a field in my database... I need it to display as the following: <a href="javascript:;" onclick="Show_Stuff('201001251351');\">Show</a> <div style="display:none;" id="201001251351">Some text here</div><br /> Something else in this bit <a href="javascript:;" onclick="Show_Stuff('201001251353');\">Show</a> <div style="display:none;" id="201001251353">Some different text here</div><br /> And more different bits <a href="javascript:;" onclick="Show_Stuff('201001251357');\">Show</a> <div style="display:none;" id="201001251357">Some more text here</div><br /> Further different bits which may include other replaced things This would be easy if I only needed to use the time value once in each replacement, but as you will see I use it twice each time and I can't figure out how to duplicate it. So in a nutshell I need to extract the bit between the [[# and #]] as a variable, then add it into both the javascript variable in the a tag and the id of the div tag and put everything between the #]] and the[[end]] in between the 2 div tags. Hope this makes sense! Any help much appreciated. I will probably kick myself later, as it'll no doubt be a blatant solution!
  17. Tried that - it didn't work. That's only necessary if you're running it within a multi query, which I'm not. As I said, it only fails when using the OO style structure, not the procedural style.
  18. I still have no fix for this. Is there really nobody out there who uses MySQL stored procedures and OO style mysqli?
  19. No, the code is correct and works. Both queries work fine on their own, it's only when I run one after the other that I have a problem.
  20. I am tearing my hair out over this: <?php $mysqli = new mysqli("localhost", "username", "password", "database"); $query1="CALL procedure1 (1)"; $insert=$mysqli->query($query1); $row = $insert->fetch_array(); print_r($row); $insert->free_result(); $query2="CALL procedure2 (1,2,3)"; if (!$mysqli->query($query2)) { printf("Error: %s\n", $mysqli->error ."<br />"); } $mysqli->close(); ?> It refuses to run the second SP giving me a "Commands out of sync; you can't run this command now" error, despite me using the "$insert->free_result();" on the first one. If I do the same as above but use procedural instead of OO style, it works fine. I don't wish to use procedural style, as I am using this within a class. I can't use the mysqli_multi_query as the second procedure relies on the information returned by the first.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.