Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. No this will only center it horizontally and he probably also wants it vertically centered
  2. and, why would you do that? The correct question is: 'why wouldn't you do that?' (and there are actually some valid responses to it). When company allegedly using OO approach to programming does not know benefits of TDD, that doesn't bode well. 'Do you do unit tests?' 'Why would you do that?' 'Do you do encapsulate fields in your classes?' 'Why would you do that?' 'Do you try to make your classes as decoupled as possible?' 'Why would you do that?' 'DRY' 'Wha...?' Why did you become a programmer? I didn't. I just visited the company on open-business day someone assigned me a seat and I'm "working" here ever since. Altough this may be funny now it's what we face almost everyday people which you have to work with who actually have no idea of what they are doing.. I knew I had to get that Engineer Degree and work for IBM
  3. Take a look at: http://www.wpdfd.com/editorial/thebox/deadcentre4.html
  4. Nothing can safe the world we are doomed the entire universe is against us: the sun, our planet, .., everybody! Unit-Testing does not safe the world it discovers bugs early in the development process (atleast if one knows how to apply it). The same applies for Continuous Integration, Acceptance-Testing and Usability-Testing. They help you to create better software for the client and maintainable software for you.
  5. It's not just single programmers it are complete companies I once had an interview with a programmer from another company when I asked them after which methodology they applied and why? He replied: We write OO because it's better.. Completly stunned I asked him if he applied Unit-Testing on which he replied: why would you do that? The companies framework went open-source a few years back and horrifying is an understatement. Something different I also came across is website deployment in less or equal to 3 consecutive days.
  6. True. But 90% is, so account for it!
  7. You can't mysql_real_escape_string is mysql only. Use addslashes instead
  8. If you are working on shared hosting you must make sure that your first thing you do is: ini_set('session.save_path', 'path/to/local/directory'); Second on the login page: function start_session($lifetime = 0) { if (0 !== $lifetime) session_set_cookie_params($lifetime); session_start(); } if (isset($_POST['submit'])) { $session_lifetime = 0; if (isset($_POST['remember_me'])) { $session_lifetime = 3600; } start_session($session_lifetime); //logic } Something different that I found working: setcookie(session_name(), session_id(), $session_lifetime); This last option creates 2 cookies the cookie created by session_start() will be destroyed upon browser-closing while the other remains active and upon next visit you will appear as logged in. View stored cookies to watch how this happens.
  9. It's a bad idea to let the user create the colour images or insert hex colour codes as they won't know how to create such an image nor do they know what HEX means. Keep It Simple!
  10. My code is just an example pseudo-code if you like. I tend to use OO as much as possible in plain/raw PHP this would be: To update the user record: if (isset($_SESSION['logged_in'])) { // only update the record if the user is actually logged in $query = 'UPDATE users SET last_click_at = now() WHERE id = ' . mysql_real_escape_string($_SESSION['user_id']); mysql_query($query, $database); } To find all logged in users: $query = 'SELECT * FROM users WHERE last_click_at BETWEEN now() - 300 AND now()'; $result = mysql_query($query, $database); $users = array(); if (false !== $result) { $resultCount = mysql_num_rows($result); if (false !== $resultCount) { $users = array_map('mysql_fetch_assoc', array_fill(0, $resultCount, $result)); } } print_r($users); An other possible way is by storing session data in the database. Then to find all logged in users it's as simple as: SELECT * FROM session WHERE modified + lifetime > now() Here's an example: http://framework.zend.com/manual/en/zend.session.savehandler.dbtable.html This also eliminates the need to update the record on each request as your session save_handler will do this for you (altough you still need to provide the implementation).
  11. Flash is a great tool however at some point someone thought they should build websites entirely in Flash and others followed and then they started complaining because it's not SE-friendly. Flash is not designed to build websites but rather animation's and video's it originally was a new way to make advertisements at small size and awesome quality Flash is not SE-friendly because it's just an object and is like an image not readable by a SE
  12. If it's the due date then my query should work
  13. Yes you need to update the user record on each request like: if ($auth->hasIdent()) {// performs challenge-key check and set's new challenge key $user->setLastClickAt(time());// performs timestamp to date transformation using strftime() $userTable->save($user); } Finding all users between the interval can go like: $users = $userTable->findUsersByLastClickBetween(5);// interval in minutes if (!empty($users)) { $view->activeUsers = $users;//$users are colored based on $user->isAdministrator(), $user->isModerator(), .. } Don't forget to index last_click_at
  14. Is date the due date? SELECT * FROM table1 t1, table2 t2 WHERE t1.id = t2.userid AND t2.payment = 'Unpaid' AND t2.date < now()
  15. That's the wrong query as he uses it to show the results of his actions. I also discourage the use of a Binary Tree if you are not familiar with it's structure. Just use the self-join: SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name as lev4 FROM category AS t1 LEFT JOIN category AS t2 ON t2.parent = t1.category_id LEFT JOIN category AS t3 ON t3.parent = t2.category_id LEFT JOIN category AS t4 ON t4.parent = t3.category_id
  16. Keep it simple: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
  17. create table user ( .. last_click_at datetime, Update the user table to indicate his last activity then using a query like: SELECT count(*) online_users FROM user WHERE last_click_at BETWEEN now() - 300 AND now() Will consider all users who clicked between now and 5 minutes ago as online @Goldeneye what do you do when they don't logout? They remain logged in forever?
  18. I have no knowledge of RPG's nor it's business rules which makes it quite hard to model a proper solution I read a background on WoW on Wikipedia altough it mentions more then the OP asked for like Factions and Faction specific races. It also probably has more then one special ability and these are probably influenced by other factors like "luck" and maybe some other stuff.
  19. I'm not into (MMO)RPG so I'm quite clueless when it comes to modelling something like this. If you still need help - you mind explaining the mechanics? Like what is BerzekerRage and PrayForAbsolution exactly? Every child-class must be able to be subsituted with it's parent class because of this you need a general method that will invoke the appropriate abilities if the character meets the requirements (enough mana, ..) -> Specific business rules for your RPG Like Mchl mentioned you could use something like (altough I fail to see how the Composite pattern fits the bill): class Character { private $race; private $class; public function __construct(CharacterRace $r, CharacterClass $c) { $this->race = $r; $this->class = $c; } public function getRace() { return $this->race; } public function getClass() { return $this->class; } } Then like Nightslyr said you can do: $player->getRace()->executeSpecialAbility(); $player->getClass()->executeSpecialAbility(); Each race and class will now what it's special ability is and would execute it upon executeSpecialAbility() invocation. But possibly you want something like: $player1->attack($player2); Then with "luck" and other things you could simulate an attack.
  20. How about: abstract class Player { .. } class OrcPaladin extends Player implements Orc, Paladin { .. }
  21. I sure do I thought I found one a while back but I forgot about it since I started using Zend_Db and Doctrine if I find it I'll post it.
  22. Creating a calendar like the above is as simple as: create table user ( id integer not null auto_increment, .. primary key (id)); create table calendar ( id integer not null auto_increment, user_id integer, content text, datum datetime, key calendar_user_id_fk (user_id), primary key (id)); I assume you can write the required PHP code using the above data and that you can create a simple table. You probably also need the queries: SELECT * FROM calendar WHERE month(datum) = $month; -- zoom to a month SELECT * FROM calendar WHERE year(datum) = $year; -- zoom year SELECT * FROM calendar WHERE week(datum) = $week; -- zoom week [ot]Als dit voor je huiswerk is mag ik je eigenlijk niet helpen [/ot]
  23. Your code mixes presentation- (html) with bussiness logic (php) First off your page1.php should be wrapped by a view: Your page1.php <!DOCTYPE ..> <html> <head> .. <title><?php print $this->title; ?></title> .. </head> <body> .. <div id="content"><?php print $this->content; ?></div> .. </body> </html> The wrapping view can be something like: class MyView { private $variables = array(); public function __set($offset, $value) { .. } public function __get($offset) { .. } public function __isset($offset) { .. } } $view = new MyView(); $view->variable = 'dog'; $view->array1 = array('cat', 'pig', 'gnu'); $view->render('page1.php'); page1.php now contains header and footer but you can put that in an include in the page1.php or use the Two-Step View pattern of Martin Fowler (http://martinfowler.com/eaaCatalog/twoStepView.html) If you don't want to write your own view you can use Smarty which is a templating engine (http://www.smarty.net/)
  24. No but I would remember it for the future. As you can see my class has all variables that your database table has as columns. This allows me to easily modify record data. You should also notice that Blog_Post has no database connection which decouples it from the database. In my example I could have a Blog class that holds a database connection for example: class Blog { private $db; //methods } class Blog_Post { private $id; private $authorId; private $title; private $content; private $timestamp; private $comments; //methods } class Blog_Post_Comment { private $id; private $author; private $title; private $content; private $timestamp; //methods } Storing data goes like: $blog->save($post); Or finding data goes like: $blog->find($post); Where a Blog_Post acts as a filter
×
×
  • 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.