Jump to content

black.horizons

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Posts posted by black.horizons

  1. Hey guys,

     

    I'm trying to write a query, which is pretty deep but here's the explanation.  I need to COUNT() the number of times an event occurs between the hours of 19:00:00 on day 1 and 07:00:00 on day 2.  This is easily solved with ...

     

    SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-09 19:00:00' AND '2009-12-10 07:00:00'

     

    The problem is that I need to do this query to cover a period of a week with a query for each pair so that I can effectively do this:

     

    SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-09 19:00:00' AND '2009-12-10 07:00:00'

    SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-08 19:00:00' AND '2009-12-09 07:00:00'

    SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-07 19:00:00' AND '2009-12-08 07:00:00'

    SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-06 19:00:00' AND '2009-12-07 07:00:00'

     

    and aggregate the results. The only difficulty with doing it this way is that I need to run the query upto 10 times for each day (as there are other conditions which need met and must be selected) which would total 70 queries just to generate one dataset...not to mention the fact that I must run each query twice as I already generate a separate dataset for data between the hours of 07:00:00 and 19:00:00.

     

    all help greatly appreciated!

  2. try putting the literal tag outside the <script type=""> and script e.g.

     

    {literal}

    <script type="text/javascript">

    <!--

      Sortable.create("results_table", {

          onUpdate:function(){

            alert(Sortable.sequence('results_table').join(''));

          }

      });

    -->

    </script>

    {/literal}

  3. i took from your saying of not using singletons for databases as you may need to use more than one connection to mean that in a multi server setup it provides a lockin that you don't need - i.e. using a singleton class limits you to one connection - which is a bad thing in a multi server setup...

  4. ok just to continue the naivity - _how_ would a singleton be avoided in a multi server setup. and how is a registry avoided in a multi server setup?  I'm actually thinking of an application I'm starting to draw requirements for that would require a multi server setup (multi database servers, multi file servers)

  5. ok i think i get it. just to confirm though...the constructor in the database class where the:

     

    if($settings){} statement lies...

     

    thats where i make the initial database connection so that the class would look a little like this:

     

    class Database
    {
       private $db_connect;
    
       private function __construct($settings = null)
       {
          if($settings)
          {
             //unserialize $settings array etc first...then...
             $this->db_connect = new mysqli($domain, $username, $password, $db_name);
          }
       }
    
       public static function getInstance($settings = null)
       {
          if(!self::$instance)
          {
             self::$instance = new self($settings);
          }
    
          return self::$instance;
       }
    }

     

     

    just a quick aside, I tend to hold my settings hardcoded in the database class, so that i don't have to pass in "settings", is this advisable? obviously in the constructor i could test for a boolean variable so if settings==true then /* store each setting in the data member variables */

  6. Nightslyr, thanks for the clear cut explaination. Fortunately i'm in final year of a software engineering course doing about code management and know about coupling/cohesion.

     

    would using the singleton approach be appropriate, or the must appropriate approach for a database object then? Or would this still create many connections on a single page.

     

    For obvious reasons I want to keep the connections as low as possible, whilst still accessing all the data I need.

  7. I've been doing PHP for over 4 years now - but only lately (last 12 months) been starting to write it as OOP.  I came to the conclusion this week that my code cannot be performing efficiently at all and I've tried to research how to do it better.

     

    Various people mention registries and singletons - but i've no idea what these are - even after reading about them!  I don't quite understand how they work - but I think I understand their purpose - and I think their purpose is exactly what I want.

     

    I _think_ that a database class as a singleton gives an application a single point of call to a database, and drastically reduces the amount of connections.

     

    currently my db access in oop goes a little like this:

     

    class db{} //this has the mysqli->connect statement and thats all

     

    class user($db){}

    //construct sets $this->db = $db;

    //this has lots of queries that take place in this class e.g.

    $db_query = $this->db->mysqli->query("select * from "); //only a dummy query!!

     

    I have several class like user each one passing in the $db, and putting queries onto it.  In my head that seems like a lot of memory is being used - especially as there are usually 3 or 4 classes - as well as the DB class being used on each page - I think that might result in 4 statements of $this->db = $db;

     

    this surely can't be right and singletons / registries sound like what i need.

     

    can anybody explain to me a) what a singleton is b) what a registry is and c) how to effectively implement them via short code sample so I can an idea.  I've seen people writing "getInstance()" functions - again I've no idea what they are so if that can be summarised too I'd be an extremely happy person!

     

  8. Hi all,

     

    I'm using Uniform Server 3.5 as my development platform. I'm currently writing an Object Oriented Web Application using PHP5(.2.3)

     

    When I run any script with try / catch I am still getting a Fatal Error telling me I have uncaught exceptions.

     

    Earlier I discovered a small way past this by using set_exception_handler and creating a function that handles exceptions, but I didn't this was a necessity - more for creating custom handling of default exceptions.

     

    All help much appreciated,

     

    Alex

  9. Hey guys - i've been using PHP for 3 years - now i'm working on a website and I want to develop it in OOP - I've written a fully blown - and pretty advanced CMS in suquential code.

     

    I've got my head round writing PHP in OOP but on my site I've a couple of areas that I don't think needs OOP'd(?) - such as selecting lists of information. For these areas how would I write the code - as putting lists for navigation in as objects I think is overkill.

     

    Any and all ideas taken on board!

  10. Couple of questions all rolled into one.

     

    What's the best method of generating PDFs? Is it by using the functions found on php.net ( http://uk3.php.net/pdf ), or is it by using another class found elsewhere e.g. PDFLib or FPDF ( http://www.fpdf.org/ ).

     

    Also i'm wondering on a scale of 1 to 10 (10 being the worst) how intensive is PDF generation, is it intensive enough to require it's own server, if this became a mass deployment ( > 5000 users ), or are the overheads small enough to keep it running on the webserver?

     

    I'd imagine the overheads are quite large, larger even than that of image generation using GD for example, but I'd like to know if anyone has any conclusive documentation out there that I could read.

     

    Thanks,

     

    Alex

  11. you need to set the cookie like you said you know how to. then what you want to be doing is testing on the login page whether that cookie has been set - so call to the cookie:

     

    $cookieusername = $_COOKIE['username'];

    $cookiepassword = $_COOKIE['password'];

     

    then pass these two (cookieusername and cookiepassword) into your login tester and if they work then the person is logged in. Not a highly secure way of doing business mind you...never store a password in a cookie, unless its a home project with nothing big in mind, and md5() your passwords anyway...at the least!

     

     

  12. ok i used a for loop e.g.

     

    for($i=0;$i<10;$i++)

    {

      echo "<input type=\"checkbox\" name=\"red[$i]\">

    }

     

    then to process:

     

    for($j=0;$j<10;$j++)

    {

      $valueofcheckbox = $red[$i];

      if($valueofcheckbox=="on")

      {

          echo "$j is ON";

      }

      else

      {

          echo "$j is OFF";

      }

    }

     

    i'm sure you can figure out how to put this in a while loop if you're using a mysql recordset.

×
×
  • 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.