Jump to content

Wildbug

Members
  • Posts

    1,149
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Wildbug's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm using Opera 10.63 under Linux, and I've just run a few tests using IFRAME. First of all, according to (the book) Dynamic HTML setting .src is a legitimate way to load a page into an IFRAME, and I can confirm it works under FF and Opera. Supposedly it's level-1 DOM and works all the way back to IE4. Secondly, how are you confirming that nothing is loading into the IFRAME? Via code or visually? If the URL of the document and the IFRAME don't share the same domain, you're not going to be able to access the IFRAME properties because of Same Origin Policy.
  2. You're not actually using arrays in that example; those are objects. You will need to use the for...in construct to loop through the properties of the objects. Here are two functions which demonstrate this. The first, getMax(), returns an object with the company name and value for the maxiumum value. The second, getMaxes(), returns an array of similar objects, in case multiple companies tied for maximum value. var supplier = { company1:{}, company2:{}, company3:{} }; supplier['company1']['eur'] = 1.1111; supplier['company1']['usd'] = 2.2222; supplier['company1']['cad'] = 3.3333; supplier['company2']['eur'] = 4.4444; supplier['company2']['usd'] = 0.5555; supplier['company2']['cad'] = 6.6666; supplier['company3']['eur'] = 7.7777; supplier['company3']['usd'] = 2.2222; supplier['company3']['cad'] = 0.9999; function getMax(currency) { var co, max = Number.NEGATIVE_INFINITY, max_co; document.writeln(max); for (co in supplier) { document.writeln(co + " " + supplier[co][currency]); if (supplier[co][currency] > max) { max = supplier[co][currency]; max_co = co; } } return { value: max, company: max_co }; } var Max = getMax("eur"); document.writeln(Max.company + ": " + Max.value); function getMaxes(currency) { var co, max = Number.NEGATIVE_INFINITY, maxes = []; for (co in supplier) { if (supplier[co][currency] > max) { maxes = []; max = supplier[co][currency]; } if (supplier[co][currency] == max) maxes.push({ value: max, company: co }); } return maxes; } Max = getMaxes("cad"); for (var i = 0; i < Max.length; i++) document.writeln(Max[i].company + ": " + Max[i].value); These functions could be written better in order to re-use them with other objects/situations. One thing you could do is remove the hard-coded "supplier" object, replace it with "this", and use the Function.call method. function getMaxes(currency) { var co, max = Number.NEGATIVE_INFINITY, maxes = []; for (co in this) { if (this[co][currency] > max) maxes = [], max = this[co][currency]; if (this[co][currency] == max) maxes.push({ value: max, company: co }); } return maxes; } Max = getMaxes.call(supplier, "usd"); for (var i = 0; i < Max.length; i++) document.writeln(Max[i].company + ": " + Max[i].value);
  3. It looks like the rightshift implementation mods the shift number by the number of bits your system is, in your case 32. At the command line on a 64-bit system; rightshifting 1 and 8 from 0 to 66: $ php -r 'foreach(range(0,66) as $n) printf("%2d (%2d): %064b\n", $n, $n % 64, 1 >> $n);' 0 ( 0): 0000000000000000000000000000000000000000000000000000000000000001 1 ( 1): 0000000000000000000000000000000000000000000000000000000000000000 2 ( 2): 0000000000000000000000000000000000000000000000000000000000000000 3 ( 3): 0000000000000000000000000000000000000000000000000000000000000000 4 ( 4): 0000000000000000000000000000000000000000000000000000000000000000 5 ( 5): 0000000000000000000000000000000000000000000000000000000000000000 6 ( 6): 0000000000000000000000000000000000000000000000000000000000000000 7 ( 7): 0000000000000000000000000000000000000000000000000000000000000000 8 ( : 0000000000000000000000000000000000000000000000000000000000000000 9 ( 9): 0000000000000000000000000000000000000000000000000000000000000000 10 (10): 0000000000000000000000000000000000000000000000000000000000000000 11 (11): 0000000000000000000000000000000000000000000000000000000000000000 ...snip... 59 (59): 0000000000000000000000000000000000000000000000000000000000000000 60 (60): 0000000000000000000000000000000000000000000000000000000000000000 61 (61): 0000000000000000000000000000000000000000000000000000000000000000 62 (62): 0000000000000000000000000000000000000000000000000000000000000000 63 (63): 0000000000000000000000000000000000000000000000000000000000000000 64 ( 0): 0000000000000000000000000000000000000000000000000000000000000001 65 ( 1): 0000000000000000000000000000000000000000000000000000000000000000 66 ( 2): 0000000000000000000000000000000000000000000000000000000000000000 $ php -r 'foreach(range(0,66) as $n) printf("%2d (%2d): %064b\n", $n, $n % 64, 8 >> $n);' 0 ( 0): 0000000000000000000000000000000000000000000000000000000000001000 1 ( 1): 0000000000000000000000000000000000000000000000000000000000000100 2 ( 2): 0000000000000000000000000000000000000000000000000000000000000010 3 ( 3): 0000000000000000000000000000000000000000000000000000000000000001 4 ( 4): 0000000000000000000000000000000000000000000000000000000000000000 5 ( 5): 0000000000000000000000000000000000000000000000000000000000000000 6 ( 6): 0000000000000000000000000000000000000000000000000000000000000000 7 ( 7): 0000000000000000000000000000000000000000000000000000000000000000 8 ( : 0000000000000000000000000000000000000000000000000000000000000000 9 ( 9): 0000000000000000000000000000000000000000000000000000000000000000 10 (10): 0000000000000000000000000000000000000000000000000000000000000000 11 (11): 0000000000000000000000000000000000000000000000000000000000000000 ...snip... 59 (59): 0000000000000000000000000000000000000000000000000000000000000000 60 (60): 0000000000000000000000000000000000000000000000000000000000000000 61 (61): 0000000000000000000000000000000000000000000000000000000000000000 62 (62): 0000000000000000000000000000000000000000000000000000000000000000 63 (63): 0000000000000000000000000000000000000000000000000000000000000000 64 ( 0): 0000000000000000000000000000000000000000000000000000000000001000 65 ( 1): 0000000000000000000000000000000000000000000000000000000000000100 66 ( 2): 0000000000000000000000000000000000000000000000000000000000000010 You'll notice that at 64, the results start again as they would have from the beginning.
  4. Credit card companies use the Luhn algorithm. I know different companies start their numbers with different prefixes, so you could adapt something similar to attach codes to regions.
  5. If you just need to match, i.e., you don't need to modify it, you could strip out the HTML before matching. I'm guessing that if you don't want <a href="">belt</a> to match, then you probably don't want <a href="">my belt is black</a> to match either, so that would rule out a custom replacement for the \b atom. If you want to replace these instances and return the modified text, you'll probably need to remove the HTML sections (leaving placeholders), run the replacement, then replace the original HTML blocks. I've done something like that before... it was a few years ago, so I would have to find the code this weekend if you want me to post it.
  6. Exactly what upp said. The function you want is window.setTimeout. I'm not sure how your application is set up, but you could set a keydown/keypress listener to reset a timer that will call a function that will set the session as inactive. Here's a simple example. Delay is in milliseconds. var timer, delay = 15 * 60 * 1000, active = true; function makeInactive() { active = false; // update the server here } function keyDownListener() { if (timer) clearTimeout(timer); if (!active) { active = true; // update the server here } timer = setTimeout(makeInactive, delay); } keyDownListener(); // start the timer explicitly // you'll also need to attach the listener to the document.
  7. First of all, I don't think you can get just any external page to load in your script. Look up "Same Origin Policy." You can circumvent this for your own site by writing a simple proxy script (server side). Aside from that issue, there are at least two ways you can get the content of another web page. The first is Ajax, the second is an IFRAME. It's possible to put an invisible IFRAME element in your document, set the src to the location you want, and then read the content once it has loaded using either the contentDocument (DOM) or contentWindow (IE) properties.
  8. There's also the onload property of IMG. You can set it to do something when the image finishes loading. If you need to do something once all of the images have loaded, you could use a counter and fire that code once the counter has reached zero. It is important that you set the onload callback before you set the src property of the image as it may not fire if the image is loaded from cache. function loadMyImages() { var counter = 0, image; function imgCallback() { if (--counter) return; // hide the "Loading" SPAN here } /* show the "Loading" SPAN here */ for (var i = 0; i < 5; i++) { image = document.createElement('IMG'); image.onload = imgCallback; counter++; image.src = "image" + i + ".jpg"; } }
  9. I find it bizarre that PHP behaves the way it does regarding method definition context and static class variables ($this vs. self). The self keyword is almost useless; if it's only ever going to refer to the class in which it was defined, why wouldn't I just use the class name explicitly? /rant How can I have a value common to an extended class be correctly referenced in an inherited method? An example case: <?php abstract class Base { static protected $table_name = "none"; public function getTableName() { return self::$table_name; } } class ChildClass extends Base { static protected $table_name = "my_table"; } $cc = new ChildClass; echo $cc->getTableName(); // outputs "none" ?> I guess I could define an abstract method in the base class that should return the tablename. What's the standard practice for this situation in PHP?
  10. (Note: I'll be away for a week, so I probably won't be reading this thread.)
  11. So you want to know if the student id from the schedule is different from the one in the template?
  12. Two options. You can add up the prices while you process your query in PHP, or you can use the SUM() function to get...wait for it... a sum. You'll have to do the SUM in a stand alone query.
  13. Date and time functions A MySQL tutorial The manual explains it in detail. There's even a tutorial. Come back when you've read it and worked out the examples for a few days.
  14. See "Date and Time Functions" in the MySQL manual. You can use the "...WHERE date BETWEEN start AND end" construct to find ranges. today = NOW() yesterday = NOW() - INTERVAL 1 DAY
  15. Wildbug

    Count

    To benchmark these, you need to take multiple execution times to get a reliable time.... something like this: <?php $loops = 100; $start = microtime(1); for ($i = 0; $i < $loops; $i++) { // put test code #1 here } echo "First way took <b>", microtime(1) - $start, "</b> seconds.<br><br>\n"; $start = microtime(1); for ($i = 0; $i < $loops; $i++) { // put test code #2 here } echo "Second way took <b>", microtime(1) - $start, "</b> seconds.<br><br>\n"; ?> With 100 loops on those queries we have been discussing, the execution times were around 0.08-0.09 seconds... which is no big deal. But if your site gets a lot of traffic, maybe you'll need to make your code as efficient as possible.
×
×
  • 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.