Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Well these only serve the purpose of an example and I am not going to correct any error because you shouldn't be using them in production environments they are not meant to. An alternate solution production ready may be Zend_Navigation. Easy to use http://framework.zend.com/manual/en/zend.navigation.html
  2. Here's an improved version: $rows = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $pid = intval($row['parent_id']); $rows[$pid][] = $row; } $root = new Menu(); foreach ($rows as $pid => $array) { foreach ($array as $row) { $id = intval($row['id']); if (!isset($rows[$id])) { $root->add(new MenuLeaf($row)); } else { $root->add(new MenuComposite($row)); } } } print $root->render(); abstract class MenuComponent { private $data = array(); public function __construct($data = array()) { $this->data = $data; } abstract public function render(); } class MenuComposite extends MenuComponent { private $components = array(); public function add($key, MenuComponent $item) { $this->components[$key] = $item; } public function render() { if (!sizeof($this->components)) return ''; $html = '<a href="#">' . $this->data['label'] . '</a><ul>'; foreach ($this->components as $component) { $html .= '<li>' . $component->render() . '</li>'; } return $html . '</ul></a>'; } } class Menu extends MenuComposite { public function render() { if (!sizeof($this->components)) return ''; $html = '<ul>'; foreach ($this->components as $component) { $html .= '<li>' . $component->render() . '</li>'; } return $html . '</ul>'; } } class MenuLeaf extends MenuComponent { public function render() { $data = $this->getData(); return '<a href="#">' . $data['label'] . '</a>'; } }
  3. Use the composite pattern to achieve this: $root = new MenuComposite(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $mc = new MenuLeaf($row); $root->addItem($mc); } print $root->render(); abstract class MenuComponent { private $_data; public function __construct(array $data) { $this->_data = new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS); } public function getData() { return $this->_data; } public function getId() { return $this->getData()->id; } public function getParentId() { return $this->getData()->parent_id; } public function addItem(MenuComponent $mc) {} public function render() { return ''; } } class MenuComposite extends MenuComponent { private $_items; public function getItems() { if (null === $this->_items) { $this->_items = new ArrayObject(); } return $this->_items; } public function addItem(MenuComponent $mc) { if (0 !== $mc->getParentId()) { // composite $this->getItems()->offsetSet($mc->getId(), $mc); } else if ($this->getItems()->offsetExists($mc->getParentId())) { // leaf $p = $this->getItems()->offsetGet($mc->getParentId()); if ($p instanceof MenuComposite) { $p->addItem($mc); } else { // convert MenuLeaf to MenuComposite $p = new MenuComposite($p->getData()); $p->addItem($mc); $this->getItems()->offsetSet($mc->getParentId(), $p); } } else { throw new Exception('Parent item with id ' . $mc->getParentId() . ' does not exist.'); } } public function render() { $list = '<ul>'; foreach ($this->_items as $id => $mc) { $list .= '<li>' . $mc->render() . '</li>'; } $list .= '<ul>'; return $list; } } class MenuLeaf extends MenuComponent { public function render() { return '<a href="' . $this->getData()->href . '">' . $this->getData()->label . '</a>'; } }
  4. add a watermark to your images.
  5. http://www.amazon.com/Understanding-Search-Engines-Mathematical-Environments/dp/0898714370
  6. You won't need a customers table because have you ever had to give your full details when you went to a restaurant? No. all required information comes down to a reservation name (which can be anything), date and time of the reservation, and the number of people accompanying you. Possible use-cases: 1. A customer cancels his reservation 2. A customer has a coupon code or some other means (birthday, ..) by which he receives a reduction on his meal 3. The owner wants to find the most popular dish 4. The owner wants to find out if all none cancelled reservations have been paid for this day, this month, .. 5. The owner wants to find the total income (excl VAT) for today, this month, year, .. 6. The owner wants to find out which is the most popular choice of payment among his customers 7. .. menu (id, name, description, price) consumption (menu_id, reservation_id) reservation (id, tabletop_id, for, at, size, cancelled) tabletop (id, name, seats) checkout (id, reservation_id, subtotal, total, paid_by, coupon_code, reduction) This is by no means the end try to find some more use-cases discuss with your teacher, your parents or visit a restaurant. You don't need all information but you should have a good idea of the basic workflow within a restaurant.
  7. item_1 through item_7 in one table is bad design. Give us some more details and I may help you normalize your database.
  8. The best would have been if you had defined your entire application in clear business rules both in terms of your application as your database. http://en.wikipedia.org/wiki/Business_rule
  9. For future reference create a binary table: a | b | -a | -b | -a+-b | -a.-b | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | -a+-b = !a||!b -a.-b = !a&&!b As you can see in the above table it only returns true when both !a & !b return true where !a || !b only returned false when both !a & !b were false
  10. Not if you use PHP you can easily determine the active page: <li<?php print isActivePage($href, $_SERVER['REQUEST_URI']) ? ' class="active"' : ''; ?>><a href="<?php print $href; ?>"><?php print $label; ?></a></li>
  11. A great help with any project is textual analysis and an ERD (entity-relationship diagram). Your text after stripping out all none db related material: I got: -- code refers to a 2-letter country code http://www.modemsite.com/56k/_ccodes.asp language (id, name, code) -- polyglot means a person who speaks many languages -- 'speak' indicates how well a person speaks that language 3 out of 5 for example where 5 is perfect or native speaker polyglot (language_id, user_id, speak) user (group_id, employee_of, street_address, ..) group job (language_id, requested_by, assigned_to, deadline) job_type (id, name) -- pph is pay per hour -- i put pph here because depending on the client they may charge more or less per hour invoice (job_id, client_id, hours, pph) -- company where an interpreter works agency (id, name, street_address, ..)
  12. That's because of how || works. I assume you want to show the not-authorized message whenever someone tries to do something while not an admin nor a staff member. Try: function sessionAuthenticate ( ) { // Are you loged in is admin, when trying to asscess this page if (!isset($_SESSION["admin"]) && !isset($_SESSION["staff"])) { // Set error message $_SESSION["message"] = "<div class='error'>You are not authorised to access the URL: <br> {$_SERVER["REQUEST_URI"]}</div>"; // After error message move to login.php header ("Location: login.php"); exit; } }
  13. Just add an additional class attribute to your tag <li class="active"><a href="index.php">Homepage</a></li> And add the CSS: .active a, a:active { background: #F00; color: #000; }
  14. Just add an additional class attribute to your tag <label for="username" class="input-mandatory">Username</label> <input type="text" name="username" id="username"> And add the CSS: .input-mandatory:after { content: " *:"; color: #C00; }
  15. session_set_cookie_params
  16. And you question is?
  17. - Invalid CSS & HTML - The video starts playing from the moment you enter the website (let the user control when he wants to hear something) - Almost all important text (logo, Beezag is an invite-only..) is contained in an image (Google can't read images as a result http://www.google.com/search?q=beezag) - No description meta tag - Titles remain the same between page switches (which adds to #3) - When I hit tab the first it selects is your sitemap on the bottom - A login form but no auto-select
  18. Post your database table structure DESCRIBE table1; DESCRIBE table2; ..
  19. Yes it does if it wouldn't REFERER would be broken your iframe is the caller which is tes1 so last REFERER for tes2 is tes1 If you want tes the remove the iframe. Don't forget the iframe makes a different request (tes1) then your own (tes)
  20. The manual could told you that: Those are 2 real advantages of PDO over MySQLi. IMO Stick with MySQLi unless you want to distribute your software for which I would recommend Doctrine or Zend_Db.
  21. Zend framework. IMO the best out there.
  22. I actually wanted to hide this kind of complexity from him Now he has to deal with <<, >>, ~ and ^ instead of only | and & function setbit($flags,$position) { return $flags|(1<<$position); } function resetbit($flags,$position) { return $flags&(~(1<<$position)); } function togglebit($flags,$position) { return $flags^(1<<$position); } function readbit($flags,$position) { return ($flags|(1<<$position))?1:0; } N-Bomb check this manual page out: http://php.net/manual/en/language.operators.bitwise.php
  23. Try this piece of code to get a hang on it: <form action="" method="post"> <label for="real_name">Show real name:</label> <input type="checkbox" name="real_name" id="real_name"> <label for="email_address">Show email address:</label> <input type="checkbox" name="email_address" id="email_address"> <label for="street_address">Show street address:</label> <input type="checkbox" name="street_address" id="street_address"> <label for="country">Show country</label> <input type="checkbox" name="country" id="country"> <label for="phone_number">Show phone number</label> <input type="checkbox" name="phone_number" id="phone_number"> <label for="cellphone_number">Show cellphone number</label> <input type="checkbox" name="cellphone_number" id="cellphone_number"> <label for="gender">Show gender</label> <input type="checkbox" name="gender" id="gender"> <label for="political_preferences">Show political preferences</label> <input type="checkbox" name="political_preferences" id="political_preferences"> <input type="submit"> </form> <?php if ('POST' === $_SERVER['REQUEST_METHOD']) { $show_real_name=1; $show_email_address=2; $show_street_address=4; $show_country=8; $show_phone_number=16; $show_cellphone_number=32; $show_gender=64; $show_political_preferences=128; $flags = 0; if (isset($_POST['real_name'])) $flags |= $show_real_name; if (isset($_POST['email_address'])) $flags |= $show_email_address; if (isset($_POST['street_address'])) $flags |= $show_street_address; if (isset($_POST['country'])) $flags |= $show_country; if (isset($_POST['phone_number'])) $flags |= $show_phone_number; if (isset($_POST['cellphone_number'])) $flags |= $show_cellphone_number; if (isset($_POST['gender'])) $flags |= $show_gender; if (isset($_POST['political_preferences'])) $flags |= $show_political_preferences; echo 'decimal: ', $flags, ' binary: ', decbin($flags), '<br><br>Public viewable data:<br>'; if ($flags & $show_real_name) echo 'real name<br>'; if ($flags & $show_email_address) echo 'email address<br>'; if ($flags & $show_street_address) echo 'street address<br>'; if ($flags & $show_country) echo 'country<br>'; if ($flags & $show_phone_number) echo 'phone number<br>'; if ($flags & $show_cellphone_number) echo 'cellphone number<br>'; if ($flags & $show_gender) echo 'gender<br>'; if ($flags & $show_political_preferences) echo 'political preferences<br>'; } ?>
  24. 1 exif if supported, 2 gd if supported and not jpeg or tiff, 3 getimagesize otherwise
  25. Some more explanation of what laffin is saying: (2^0 = 1) = 0001 (2^1 = 2) = 0010 (2^2 = 4) = 0100 (2^3 = = 1000 You notice a pattern in the above code 0001, 0010, 0100, 1000 the one moves from right-to-left. Now each place represents wether or not he wants to show a certain field for example email, birthday, friendlist, .. $birthday = 1; // 1 = 0001 $email = 2; // 2 = 0010 $friendlist = 4; // 4 = 0100 list($bitflags) = mysql_fetch_array($result, MYSQL_NUM); $bitflags = intval($bitflags); // assume: $bitflags = 3 = 0011 (user wants to show email and birthday but nothing else) if ($bitflags & $email) { // 0011 & 0001 = 0001 (true) .. } if ($bitflags & $birthday) { // 0011 & 0010 = 0010 (true) .. } if ($bitflags & $friendlist) { // 0011 & 0100 = 0000 (false) .. } You need to understand binary math to be able to understand why this works: or: 0 | 0 = 0 0 | 1 = 1 1 | 0 = 1 1 | 1 = 1 and: 0 & 0 = 0 0 & 1 = 0 1 & 0 = 0 1 & 1 = 1 xor: 0 ^ 0 = 0 0 ^ 1 = 1 1 ^ 0 = 1 1 ^ 1 = 0
×
×
  • 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.