Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Kids these days aren't happy if it isn't an iPhone.. In my time we had sticks and stones, and we made chess pieces out of it. And then beat the crap out of the other kids with them, since none of us was smart enough to figure out what the pieces were for anyway.. Good times.
  2. Prizes? Who needs prizes? I am in it for the glory! Something like a badge with the ratio of solved problems beneath my name will suffice That said, the challenges have to be open enough that everyone has a chance of solving it or are we really going to discriminate as a community and create A, B, and C groups? And it has to be done in any language supported on this forum. So Fizzbuzz in Python or Perl is a no-go. This should have a thread on it's own.
  3. LOL. All you want to do is team up. And everyone here is advicing you to read books and tutorials... Me thinks people want to increase their post count.. You can always PM me if you have any OO related issue you want to discuss. Keep in mind though that, although I may sound like one, I am not an OO expert
  4. I'm a fan myself Here's an OOP version (with all Stargate "business" logic build in) class Stargate { public function dial(Stargate_Address $address, Stargate_Energy $energy) { try { $this->obtainLock($address); return $this->generateWormhole($energy); } catch (LockFailedException $e) { $this->disengageChevrons(); throw new DialFailedException($e->getMessage(), $e->getCode(), $e); } catch (InsufficientEnergyException $e) { $this->disengageChevrons(); throw new DialFailedException($e->getMessage(), $e->getCode(), $e); } } private function obtainLock(Stargate_Adress $address) { $pos = 1; foreach ($address as $chevron) { try { $this->engageChevron($pos++, $chevron); } catch (ChevronLockFailedException $e) { throw new LockFailedException($chevron->toGlyph() . ' could not lock.'); } } } private function engageChevron(Stargate_Chevron $chevron) { // logic here } private function generateWormhole(Stargate_Energy $energy) { // do we have enough energy to create the wormhole? // or throw new InsufficientEnergyException(); } } try { $stargate = new Stargate(); $wormhole = $stargate->dial(Stargate_Address::generate()); $wormhole->passThru('something'); } catch (DialFailedException $e) { echo $e->getMessage(); }
  5. Here's a shorter version of your function with the same result. $length number of unique values. function stargate_generate_address($length = 7, $possibilities = 36) { $chevrons = array_rand(range(1, $possibilities), $length); shuffle($chevrons); return implode('-', $chevrons); }
  6. Unless you declared the variable static. function foo() { static $bar = 1; echo $bar++; } foo();//1 foo();//2 foo();//3 foo();//4
  7. From Wikipedia: You are still using the PHP implementation for sessions (ie, the filesystem) also options like cache lifetime and such are missing. It's thus misleading.
  8. http://bugs.mysql.com/bug.php?id=34665 See the response by "[4 Mar 2008 11:24] Martin Hansson" A viable alternative is: CREATE TEMPORARY TABLE temp ENGINE=MEMORY ( SELECT foo FROM bar WHERE bat = baz ) UNION ( SELECT foo FROM bar WHERE bat = baz ) Then SELECT * FROM temp INTO OUTFILE ... DROP TABLE temp; EDIT: SELECT * FROM ( (SELECT foo FROM bar) UNION (SELECT baz FROM bat) ) as dummy INTO OUTFILE 'foo.csv' Works equally.
  9. Also the class name implies it's something it's not and your class actually violates SRP and the OCP principle. Since your class is responsible for both _SESSION and encryption of the data. Everytime the encryption of your session changes you have to go in the sessioncache class and change it, which is more prone to break existing code.
  10. Belgium is the king of beers. Try a Duvel when you ever come to visit.
  11. Yeah try to explain that to a new PHP programmer. When you encourage him to look out for a PHP 5.3 book and ignore the PHP 6 ones as they are older than the previous... Or that they bought a book on PHP 6 and then ask me where they can download PHP 6 as they are unable to find it... and then the weird look they give you when you tell them: It's PHP 5.3.. partially.
  12. Since there is too much code to figure out where you are actually multiplying/adding the totals, here's some example code: echo calculate_total(array(215 => '', 213 => 1, 212 => 2, 214 => '')); function calculate_total(array $array) { $total = 0; foreach (array_filter($array) as $key => $value) { $total += $key * $value; } return $total; } The function cleans the array of unwanted values (empty). Then for each of the remaining values it will multiply the key with it's value and add it to the total.
  13. Or worse they are just being re-labeled. I found a book labeled PHP 5.3 that mentions ereg() whilst being deprecated, encourages to write SQL injectable queries, and does not mention lambda functions once or anything else of the new stuff. The author should be shot! (But kill the publisher first!) PS I can not be held responsible if either the author or the publisher should be harmed or killed. Will that hold in court?
  14. I've seen it be done on at least one occasion like: class ExampleFoo { private $bar; public function doStuffWithBar() {} private $bat; public function doStuffWithBat() {} }
  15. Currently it's just a dummy but you can replace it with Smarty. You can use it in your <action-name>Action() methods. public function insertAction() { if ($this->request->offsetExists('MM_insert')) { /** process logic here **/ /** onError: $this->view->assign('error', $error); **/ /** onSuccess: header('Location: somewhere'); exit; **/ } $this->view->display('beheerder/insert.tpl'); }
  16. require 'BeheerderDAO.php'; class BeheerderController { public $view; public $request; public function __construct() { $this->dao = new BeheerderDAO; } public function insertAction() { /** your code here **/ } public function errorAction() { /** your error code here **/ } public function dispatch(array $input, $view) { $this->view = $view; $this->request = new ArrayObject($input); if (!isset($input['action'])) { return $this->errorAction(); } $methodName = strtolower($input['action']) . 'Action'; unset($input['action']); if (!method_exists($this, $methodName)) { return $this->errorAction(); } $this->$methodName(); } } /** * Is this file being called directly? ie http://domain/BeheerderController.php */ if (basename($_SERVER['REQUEST_FILENAME']) == basename(__FILE__)) { require 'MyTemplateView.php'; $_REQUEST = $_GET; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $_REQUEST = $_POST; } $controller = new BeheerderController; $controller->dispatch($_REQUEST, new MyTemplateView); } Of course you will need to abstract/move both the above if() statement and the dispatch() method if you want it to work in other cases as well. The DAO could look something like: class BeheerderDAO { public $conn; public function __construct() { require 'db-config.php'; $this->conn = mysql_connect($db['host'], $db['user'], $db['pass']); if ($this->conn === false) throw new RuntimeException('Failed to connect to the database server.'); if (mysql_select_db($db['name'], $this->conn) === false) throw new RuntimeException('Failed to select the specified database.'); } public function save($naam, $paswoord) { $sql = "INSERT INTO beheerder (naam, paswoord) VALUES ('%s', '%s')"; $frm = sprintf($sql, $naam, $paswoord); $res = mysql_query($sql, $this->conn); if ($res === false) throw new RuntimeException('Query failed. Beheerder has not been saved.' . "\r\n\r\n" . ' QUERY: ' . $frm . "\r\n\r\n" . ' ERROR: ' . mysql_error($this->conn)); return true; } } This setup is not ideal and violates a few principles (OCP, SRP, Encapsulation, comes to mind) but it should be simple enough for you to understand and pick up.
  17. Here are the files with all errors corrected. Your code is not nearly close to an OO MVC architecture. BeheerderForm.html <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="validateBeheerderPasw.js" type="text/javascript"></script> <link href="validateBeheerderPasw.css" rel="stylesheet" type="text/css"/> <title>BeheerderForm</title> </head> <body> <form action="BeheerderController.php" id="form1" name="form1" method="POST"> <div align="center"> <table width="200" border="1"> <tr> <td>naam</td> <td><label for="TFnaam"></label> <input type="text" name="TFnaam" id="TFnaam" /></td> </tr> <tr> <td>pasw</td> <td><label for="TFpasw1"></label> <input type="password" name="TFpasw1" id="TFpasw1" /></td> </tr> <tr> <td>herhaal pasw</td> <td><span id="spryconfirm1"> <label for="confirmpasw"></label> <input type="password" name="confirmpasw" id="confirmpasw" /> <span class="confirmRequiredMsg">A value is required.</span><span class="confirmInvalidMsg">The values don't match.</span></span></td> </tr> <tr> <td> </td> <td><input type="submit" name="Bvoegbeheertoe" id="Bvoegbeheertoe" value="Submit" /></td> </tr> </table> </div> <input type="hidden" name="MM_insert" value="form1" /> </form> <script type="text/javascript"> var spryconfirm1 = new Spry.Widget.ValidationConfirm("spryconfirm1", "TFpasw1"); </script> </body> </html> BeheerderController.php <?php require_once('Beheerder.php'); function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } class BeheerderController {/* this is doing what exactly? Sit and look pretty? */} if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $beheerder = new Beheerder(GetSQLValueString($_POST['TFnaam'], "text"),GetSQLValueString($_POST['confirmpasw'], "text")); // fatal error: Call to a member function setObj() on a non-object in C:\wamp\www\BeheerderController.php on line 41 // Notice: Undefined variable: beheerder in C:\wamp\www\BeheerderController.php on line 41 $beheerder->setObj($beheerder); } Beheerder.php <?php require_once('BeheerderDA.php'); class Beheerder { private $naam; private $paswoord; private $aB; function __construct($naam, $paswoord){ $this->naam = $naam; $this->paswoord = $paswoord; } function setObj ($aB){ $this->ab = $aB; } } $aBeheerderDA = new BeheerderDA (); $aBeheerderDA->saveBeheerder($aB); function getBeheerderNaam () { global $naam; return $naam; } function getBeheerderPaswoord() { global $paswoord; return $paswoord; } BeheerderDA.php <?php require_once('DBconnQualifield.php'); require_once('Beheerder.php'); class BeheerderDA { private $aB; private $naam; private $paswoord; public function __construct() {} public function saveBeheerder ($aB){ $this->aB = $aB; } } $naam = getBeheerderNaam (); $paswoord = getBeheerderPaswoord (); if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 1 $insertSQL = sprintf("INSERT INTO beheerder (naam, paswoord) VALUES ('%s', '%s')",$naam,$paswoord); mysql_select_db($database_DBconnQualifield, $DBconnQualifield); $Result1 = mysql_query($insertSQL, $DBconnQualifield) or die(mysql_error()); } mysql_select_db($database_DBconnQualifield, $DBconnQualifield); $query_RSvoegbeheerdertoe = "SELECT * FROM beheerder"; $RSvoegbeheerdertoe = mysql_query($query_RSvoegbeheerdertoe, $DBconnQualifield) or die(mysql_error()); $row_RSvoegbeheerdertoe = mysql_fetch_assoc($RSvoegbeheerdertoe); $totalRows_RSvoegbeheerdertoe = mysql_num_rows($RSvoegbeheerdertoe);
  18. You may want to edit ( icon) your post (or ask a mod) and remove your e-mail address otherwise spam bots will be glad to fill your inbox for you!
  19. Sorry, we don't do that. We'll be glad to help, just post your question on the forum, give everyone a chance to answer.
  20. No ALWAYS use double quotes for attribute values. Worst case you could still use this: echo <<<HTML <table border="0" style="height:100%;width:570px;border:solid 1px #BBB"> HTML;
  21. Don't use PHP to echo out HTML. Use PHP only for PHP specific parts (echo a variable, calculate a value, if/else, ..). <?php /* Copyright (C) 2009 Murad <Murawd> Josh L. <Josho192837> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ // Must rewrite ?> <fieldset> <legend> Manage User </legend> <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> <tr class="navtitle" style="height:25px"> <th style="width:auto">Mute A User From Posting</th> </tr> <tr> <td align="center" class="tdbox"> Search for the profile name you wish to mute. </td> </tr> <tr> <td align="center"> <form method="post" action=''> <input type="text" name="name" /> <input type="submit" name="search" value="Search" /> </form> </td> </tr> <tr style="height:25px"> <td class="tdbox"> <span style="float:left"> <a href="?cype=admin">Back To Administration Control Panel</a> </span> <span style="float:right"> <a href="?cype=admin&page=unmuteuser">Unmute User</a> </span> </td> </tr> </table> </fieldset>
  22. Shitty numbers.. Am I the only one who thinks that study smells..?
×
×
  • 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.