Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. How about instead of making the value 1 or 0, you make it 'id' or 0?
  2. The point of a foreach loop is to loop through an entire array, where you don't necessarily know how many elements there are. If you already know what array elements and their keys you want to use, then you don't need a foreach loop. You can use an individual element as a regular variable by its key. Example: $array = array('a'=>1,'b'=>2,'c'=>3); echo $array['a']; // output: 1
  3. Nothing has changed from php4 to php5 on that count. Something else must have changed. If the file is not uploading, you should be getting a warning. If you are not getting a warning, turn your error reporting on: error_reporting(E_ALL); Try running the top part of your script by itself (comment out the rest or remove it), with error reporting turned on.
  4. The problem is that if you're working in a multi-user environment (more than one person accesses the page), there is no way you can guarantee the next id is gonna be the same thing you initially looked up. Easiest 'workaround' is to go ahead and do a preemptive table insert as a placeholder, so that if someone else comes along they don't grab it. Problem with that solution though is that if it turns out you don't need it, it's taking up unnecessary space. You can turn around and delete it no problem, but then you're going to have ids that skip sequence a lot, which may or may not be an issue to you. IMO your best option is to sit down and really think about whether you need to know the next id in the first place, and try to work it so you don't.
  5. waveMagicWand(); // <--no need to pass anything, it just knows.
  6. Thing is, when you've been here long enough and answered questions enough times, there isn't really a whole lot that gets asked that you don't know the answer to, just from having answered the same damn thing 100 times before. So tbh, if someone's question isn't being answered, chances are overwhelmingly high that its not being answered because they didn't ask the question properly in the first place. But it's one of those paradox things, mutually exclusive sort of things. If you are smart enough to ask your question properly, you are probably smart enough to at least figure out the solution on your own, in the first place. Not saying smart people don't need to ask questions sometimes...just saying...chances are...
  7. look at sasa trying to mash a foreach into one line. That's like a fat lady trying to wear spandex! For shame.... Here's your averages using same benchmark. Looks like corbin's deals with smaller strings slightly faster, but yours scales slightly better than his.
  8. okay well are you using the right column name? You are using 'points' as the column name and in your query you are using 'points' as the table name. Is that really how you have your table setup?
  9. you are using $row instead of $results
  10. You can just add AND/OR to the beginning or end of each string and chop off the last 3 or 2 chars after your conditions, using substr for instance. Or instead of doing $query .= ... each condition, do like $subquery[] = .... and then after the last condition, you could do $query .= implode('AND', $subquery);
  11. Take it up with smf. It's their script, not ours. Please read rules for posting here. Thread closed.
  12. ... where column like '...' AND column like '....' ... where column like '...' OR column like '....'
  13. first thing I notice is at the end, you aren't actually executing that last query, just assigning it to $query.
  14. btw this is my host's server info: http://74.54.71.140/~netadmin/
  15. 10 'layers' 100 'layers'
  16. hmmm...apparently it's faster for me to separate the calls.... you did kick my ass in the speed test when I reduced it: <?php // corbin's function function str_to_nested_array($string) { $e = explode('.', $string); $a = array(); $parent =& $a; foreach($e as $v) { $parent[$v] = array(); $parent =& $parent[$v]; } return $a; } // crayon's function function strToNestedArray($string) { eval('$structure[\'' . implode('\'][\'', explode('.',$string)) . '\'] = array();'); return $structure; } $str = "path.to.something"; echo "100k call * 10 benchmarking: <br/><br/>"; echo "Crayon Test<br/>"; for ($y = 0; $y < 10; $y++) { $start = microtime(true); for ($x = 0; $x < 100000; $x++) { $structure = strToNestedArray($str); } $time = microtime(true) - $start; echo $time . "<br/>"; } echo "<br/>Corbin Test<br/>"; for ($y = 0; $y < 10; $y++) { $start = microtime(true); for ($x = 0; $x < 100000; $x++) { $array = str_to_nested_array($str); } $time = microtime(true) - $start; echo $time . "<br/>"; }
  17. Yeah I knew that would happen. Final code: function strToNestedArray($string) { return eval('$structure[\'' . implode('\'][\'', explode('.',$string)) . '\'] = array();'); } corbin's is a little faster but come on, like 0.4s over 100k times is not even worth mentioning, and let's face it, mine is sexier.
  18. Okay corbin, you said 100k runs, right? Looks like my cleaned up version averages at 1.95s. Lot faster than before, but yours still wins :\
  19. Okay I cleaned mine up a bit. How does this compare? $string = "Paths.Images.Icons"; $nodes = explode('.',$string); $eval = '$structure[' . implode('][', $nodes) . '] = array();'; eval($eval);
  20. I can see you. But then, I have ultrascopic-heat-detection-dna-anal-izing goggles.
  21. Don't be jealous
  22. I like living dangerously.... $string = 'Paths.Images.Icons.X'; $nodes = explode('.',$string); $c = count($nodes) + 1; $eval = '$structure = array(\'' . implode("' => array('", $nodes) . "' => array(" . str_repeat(")", $c) . ";"; eval($eval); echo "<pre>"; print_r($structure);
  23. Well I'm not the only one who does it, so you're still shooting blindfolded. Nonetheless, I do think it's retarded that smf adds that "+$x hidden" to the list. Kind of defeats the purpose of hiding. I feel like I'm playing a game of blind man's bluff or something.
  24. ....and that's exactly why I have my online status set to hidden. I used to get bombarded with PMs all day long that started out with those words.
×
×
  • 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.