Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. if (totalItems <= 35) { return 49; }is wrong and should probably be: if (totalItems <= 35) { return (totalItems / 35) * 49; }but i don't know the exact requirements, so don't simply copy/paste this and think about how it is written and correct where necessary. It is not because someone on the internet gave you a working example that is the be all and end all of it. People make mistake, those on the internet do it even more.
  2. No. I had already updated my code above. Here's a demo: http://jsfiddle.net/MKVR3/1/
  3. One way you could do it is, you create a new function that fills out the other fields in your form: function updatePricesOnClick(form) { form.pricePerUnit.value = calculatePricePerUnit(form.totalItems.value); form.price.value = calculatePrice(form.totalItems.value); }Your form would then look like: <form action="#"> <input type="text" name="totalItems" id="totalItems"> <input type="text" name="pricePerUnit" id="pricePerUnit"> <input type="text" name="price" id="price"> <input type="submit" onclick="updatePricesOnClick(this.parentElement); return false;"> </form>When you fill out the first field and press submit the other fields will be filled in. When you write code in the future make sure you separate the code that does calculations (or other app-related heavy-lifting like querying a database) and the code that displays things on the screen. Developers call this "separation of concern". EDIT: de-VB'ed it.
  4. function calculatePrice(totalItems) { if (totalItems < 1) { return 0; } if (totalItems <= 35) { return 49; } // we have more then 35 items // the first 35 go for 49 pound // all others (totalItems - 35) go for 0.85 return 49 + (totalItems - 35) * 0.85; } function calculatePricePerUnit(totalItems) { return (calculatePrice(totalItems) / totalItems).toFixed(2); } calculatePrice(35); // 49 calculatePrice(36); // 49.85 calculatePrice(400); // 359.25 calculatePricePerUnit(400); // 0.90EDIT: apparently I misinterpreted
  5. In a terminal type: $ sudo nano /etc/hostsThis is something that isn't normally there and is a technique employed when using one of their products illegally. Removing the rule means your adobe products will stop working.
  6. Use mysql workbench to sync your database. MySQL Workbench Tutorial
  7. English please. And what exactly is the problem?
  8. Since it a SEO heavy website it's best to separate route from the controller otherwise you'll be renaming your controllers alot. Using silex or some other framework: $silex->get('/Home', function() { .. }) ->get('/PropertyOwner/OwnerFaq', function() { .. });
  9. You come here for help and when people give it, you tell them they are wrong while in fact they are correct. Fuck off!
  10. That's correct. Of course there are some things to consider when doing this, like you should block all incoming traffic and refer them to a maintenance page. You should keep track of changed files and the changes to the database should be possible to be reversed. So it's best to leave the decision of updating to the user and deleting database fields should be avoided.
  11. Put the file under the webroot. PHP can still read/write it, but you can't request it through a browser.
  12. Same as topic: http://forums.phpfreaks.com/topic/283709-my-first-class/?do=findComment&comment=1457483 with the same answer.. If you are going to use objects at least learn to use them properly: $cheeseMen = new TrainSloppyCheeseMen($amount); $cheeseMen->getTurns();Where getTurns contains your switch code and operates on $this->amount
  13. Try out our beta testing section, provide the link, an owner verification link, and a user/pass to play with, a lot of members here are quite good at finding exploits/breaking things.
  14. The X-Requested-With is send by all popular javascript libraries. Put it in comments and it would still have the same effect.
  15. https://github.com/geocoder-php/Geocoder Simply chain Google, Yahoo, MapQuest, OpenStreetMaps, etc.. If you hit your limit, it simply selects the next one in the chain.
  16. Basically your script would call a script on your server, passing the version number. Something like: $latest_version = file_get_contents('http://yourdomain.top/get-latest-version.php?version=' . $current_version); switch (version_compare($latest_version, $current_version)) { case 0: // equal echo 'You have the latest version'; break; case 1: // newer echo 'Update to version ' . $latest_version; break; }To get the update patch is a little more difficult. Assuming you use git and tag your releases with the version numbers you can: $version = $_GET['from_version']; $filename = $_GET['filename']; // validate $version and $filename exec('git diff --name-only ' . $version . ' HEAD', $output); // iterate over $output to get all $changed_files $temp = tempnam('/tmp', 'zip_'); $zip = new ZipArchive(); if ($zip->open($temp)) { foreach ($changed_files as $file) { $zip->addLocalFile($file); } $zip->close(); } // send it as a download header('Cache-Control: private'); header('Content-Disposition: attachment; filename=' . $filename . '.zip'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($tempnam)); header('Content-Transfer-Encoding: binary'); readfile($tempnam);The calling script then unzips the file and overwrites all files. Updating the database is a little more tricky. Your script would need to know how the database "should" look to be able to generate the alter table statements, you can do this using Doctrine's DBAL which allows you to define your tables in PHP code and then run a diff against the actual database to get the needed changes or you can try write it yourself: $tables = array( 'table1' => array( 'fields' => array( 'field1' => array('mysql' => 'INTEGER UNSIGNED NOT NULL AUTO_INCREMENT', 'sqlite' => '..', ..), .. ), 'indexes' => array( 'index1' => array('..') ), ), 'table2' => array( .. ) );then iterate over each table, does it exist? if not, create the table and the fields and it's indexes otherwise iterate over all fields and indexes. If you come across a field that does not exist in the fields array then delete it, if the field is not in the database, create it, if it exists check if the definition matches. update if it doesnt.
  17. Reformatted your code and corrected the misspelled reflector instances. $csLength = 110; $cs = range(1, $csLength); $reflectorIn = range(1, $csLength); $reflectorOut = range(1, $csLength); shuffle($cs); shuffle($reflectorIn); shuffle($reflectorOut); function generateReflector() { global $reflectorIn, $reflectorOut; $resultOut = array(); for ($i = 0; $i < count($reflectorIn); $i++) { testOutput($i, $reflectorOut[$i]); } for ($i = 0; $i < count($reflectorIn); $i += 2) { array_push($resultOut, $reflectorOut[$i] . "," . $reflectorOut[$i + 1]); } echo "<br />Input: \n"; for ($i = 0; $i < count($reflectorIn); $i++) { echo "<item>" . $reflectorIn[$i] . "</item>\n"; } echo "<br />Output: \n"; for ($i = 0; $i < count($resultOut); $i++) { echo "<item>" . $resultOut[$i] . "</item>\n"; } } function testOutput($currentPosition, $currentValue) { global $reflectorIn, $reflectorOut; if ($currentPosition != 0) { if ($reflectorIn[$currentPosition - 1] == $currentValue) { swapOutput($currentPosition, $currentValue); } } if ($currentPosition < count($reflectorOut)) { if ($reflectorIn[$currentPosition + 1] == $currentValue) { swapOutput($currentPosition, $currentValue); } } if ($reflectorIn[$currentPosition] == $currentValue) { swapOutput($currentPosition, $currentValue); } } function swapOutput($currentPosition, $currentValue) { global $reflectorIn, $reflectorOut; $endSwap = false; while (!$endSwap) { $keys = array_rand($reflectorOut); $newKey = $keys[0]; $newValue = $reflectorOut[$newKey]; if ($newKey != 0) { if ($reflectorIn[$newKey - 1] == $currentValue) { continue; } if ($reflectorIn[$newKey - 1] == $newValue) { continue; } } else if ($newKey < count($reflectorOut)) { if ($reflectorIn[$newKey + 1] == $currentValue) { continue; } if ($reflectorIn[$newKey + 1] == $newValue) { continue; } } else if ($reflectorIn[$currentPosition] == $currentValue) { continue; } else { $reflectorOut[$newKey] = $currentValue; $reflectorOut[$currentPosition] = $newValue; break; } } }
  18. Inspect the form through your browser and copy what's in the action attribute. The form is probably using method="post" so you can mimic the form using curl: http://davidwalsh.name/curl-post Use a regex to get the cd-key from $result.
  19. You need JavaScript for this. <form action="" method="post"> <input type="button" name="button1" value="1" class="increase-value"> </form> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $('.increase-value').click(function() { var $this = $(this); $this.val(parseInt($this.val(), 10) + 1); alert($this.val()); }); </script>
  20. What is it exactly that you want to match? What is your current code? $regex = "/Let'?s all go on holiday (: )?America/i"; foreach (array("Let's all go on holiday : America", "Lets all go on holiday America") as $text) { if (preg_match($regex, $text, $matches)) { echo '<div style="color: green">' . $text . '</div>'; } else { echo '<div style="color: red">' . $text . '</div>'; } }
×
×
  • 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.