Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. What about to store hundredths value in a separate INT column ? Then he loses the flexibility of for example sorting
  2. You mean: list($value) = mysql_fetch_row($sql);?
  3. ignace

    Sorting

    What does that even do? Create +------------------+---------+ | # ____________| VOTES_ | +------------------+---------+ |1_____________ | 99 ____| +------------------+---------+ |2_____________ | 55 ____| +------------------+---------+ As derived from SELECT name, votes AS votes, @num := @num +1 AS Rank FROM `servers` a, ( SELECT @num :=0 )b ORDER BY votes DESC LIMIT 0 , 10 There is no need for MySQL to create the rankings if they are merely for show
  4. Store it as a DECIMAL and calculate it like: d = (h . 60 ^ 2) + (m . 60) + s + (n . 1 / 60) function time2dec($hours, $minutes, $seconds, $hundreths) { return $hours * 3600 + $minutes * 60 + $seconds + $hundreths * 1 / 60; // 1/60 ~ 0.017 }
  5. No you explained it quite well apparently you didn't understand what I told you: class Base { /* Might have some methods to load different classes, packages, etc.. */ } Your description of the Base class clearly shows a violation to the SoC (Separation of Concerns) as your controller may not and should not load classes instead should be done through a specialized Loader class or AbstractFactory. The controller single responsibility is to match a model and a view for a given request like my registration example.
  6. It should be: SELECT * FROM accommodation WHERE lat > (base_lat - 0.2) AND lat < (base_lat +0.2) AND long > (base_lon - 0.2) AND long < (base_lon+0.2) Enclosing it between quotes made it convert from string to integer which would result in: lat > base_lat AND lat < base_lat AND long > base_lon AND long < base_lon
  7. Using a little trick you can have up to 3^10 (=59049) possible combinations just by using 2 hands 3^5 (=243) if you only use one. The values are indicated by holding your finger down (0), half-up (1), full-up (2)
  8. Alternatively you could use scandir
  9. ignace

    Sorting

    SELECT votes FROM table ORDER BY votes DESC $i = 1; while (list($votes) = mysql_fetch_row($result)) { echo $i, ' ', $votes, '<br>'; }
  10. intval() converts the input to an integer thus 192.186.1.1 would return 192 I doubt that that was what the OP had in mind when he wrote it He probably was hoping it secretly called ip2long
  11. $row_Recordset1['Price_75mm'] * 1.1
  12. date('m,d,Y,h,i,s',mktime(0, 0, 0, 9, 19, 2009)-time()); -1*(mktime(0, 0, 0, 9, 19, 2009)-time()); Makes no sense at all in the first case you subtract the current timestamp from a timestamp in the past (leading to a negative number) then the second you compensate that by multiplying it with -1 (which translates to abs(mktime(0, 0, 0, 9, 19, 2009) - time())) If you wanted the delta why not just: time() - mktime(0, 0, 0, 9, 19, 2009)?
  13. I forgot to mention that you don't need an OOP design for most websites you'll develop as they generally apply almost no business-rules. You get real benefits from OOP design when you develop software for larger to enterprise companies (in this case you'll be part of a team)
  14. Being able to access everything anywhere in your application will cause a serious amount of overhead not to mention the inflexibility of the application. I doubt you truly grasped the meaning of MVC as you mention a base class that has access to everything anywhere (so I assume it can also access your db) When you develop an application you must always adhere to laws (Law of Demeter, Separation of Concerns, ..) These laws will help you to write high-cohesive, loose-coupled, flexible software. These principles are also present in the MVC pattern. When using the MVC we apply: "Skinny Controller, Fat Model" to give you an idea of what we mean by that I'll give you an example: class UserController extends ActionController { public function registerAction() { $user = new User();//value-object (pattern) $user->username = 'username'; $user->email = 'my-email'; $model = new UserTable();//table data gateway (pattern) $model->save($user); } } Both $model and $user are models, they get that name as they are part of the domain-model (the models are the heart of all business-logic as they adhere to business-rules (:a user must validate his e-mail address prior to login) Altough the model may use a database to retrieve/store this information it generally is kept dumb (which means it uses an object with a pre-defined interface but doesn't know anything about it's implementation nor should it care) so that the model may be using a db, a flat-file, or a service.
  15. How do you mean all codes of colors? All 16,777,216 (=16^6) colors?
  16. if (isset($_GET['view'])) {//they want to view stuff //.. } else if (isset($_GET['modify'])) {//they want to mod stuff //.. } //..
  17. $fplan = array ( 'RP-151' => '90', 'RP-171' => '100', 'RP-172' => '150' ); $keys = array_keys($fplan); foreach ($keys as $key) { echo '<input type="radio" name="plan" value="', $key, '">'; } if (isset($_POST['plan'])) { $plan = $_POST['plan']; if (isset($fplan[$plan])) { echo 'You\'ve chosen product ', $plan, ' and the price is ', $fplan[$plan]; } }
  18. document.getElementById("txtfromdate").setAttribute("value", "");
  19. $ids = array(); $query = "SELECT id FROM inventory WHERE username = '$target->username'"; $result = mysql_query($query); if ($result) { while (list($id) = mysql_fetch_row($result)) { $ids[] = $id; } } $query = "UPDATE inventory SET username = '$username' WHERE username = '$target->username'"; $result = mysql_query($query); echo 'Rows updated: ', implode(', ', $ids);
  20. You'll need PHP 5.3.0 I can't solve this one. If that's not possible you'll have to look for a more lengthier option although my code will provide a nice base.
  21. version_compare('5.3.0', PHP_VERSION, '>') ? $datetime->modify(date(DateTime::ATOM, $timestamp)) : $datetime->setTimestamp($timestamp);
  22. Install Apache as a service and create a new VirtualHost (http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost) <VirtualHost *:80/></VirtualHost> This will catch all traffic going through port 80 direct it to your application: <VirtualHost *:80/> DocumentRoot /var/www/.. </VirtualHost> Check if they have valid login credentials if not show the login form if successful load the website (file_get_contents() presumably do not use header() as it will create an infinite loop)
  23. month IN ('January', 'February', ...)
  24. Ok if you don't believe me, the PHP manual says: -- http://www.php.net/manual/en/function.trigger-error.php
×
×
  • 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.