Jump to content

black.horizons

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Everything posted by black.horizons

  1. fenway, looks like that should do the job. thanks very much - one more bookmark added to my browser!
  2. is it possible to do that? if so can you provide some example of grouping by arbitrary time periods?
  3. 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!
  4. i just didnt think that was a particularly secure way of going about it. storing a user id in a session? i use a md5 hash in the session and look that up in the db - if they match then user is logged in. maybe im wrong about the secure thing?
  5. ok so gmail allows me to login at computer X using Firefox leave that session open and login using IE8 - and the two sessions can work simultaneously. i can then also use computer Y to login at the same time and the sessions still work!!
  6. Hi guys, I've been racking my brains on this one...just trying to figure out how to enable multi simultaneous logins like Google Accounts manages to do. I've also trying to understand how non session based login works...any thoughts on this is/should be done?
  7. put {debug} at the top of your .tpl page and paste in what the popup window says...(if you dont get a popup disable your popup blocker!!)
  8. 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}
  9. ok, so how would i go about writing an OOP database class without the use of a singleton. are you suggesting that each the database object is passed into each class then and referenced that way?
  10. 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...
  11. 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)
  12. given my relatively basic php database access systems - i have currently never come across the need to have more than one connection. i'm perhaps showing naivity here - but when would you need more than one connection?
  13. 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 */
  14. 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.
  15. 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!
  16. i think i'll stick with arrays then! i appreciate the help - think i'll mark this one solved!
  17. i'm using PHP5. I have an organisation class which has several methods each returning an array of data that is selected from a database and parsed (several calculations are made on the returned data). should i be using objects instead?
  18. Hi, I'm writing an application using OOP. At the minute the majority of my functions that return a large amount of information do so using an array. I'm wondering, should I be using objects though? TIA, Alex
  19. guys thanks very much. should have "solved" this earlier. i'm now using smarty and loving it!
  20. 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
  21. 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!
  22. 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
  23. 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!
  24. 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.
  25. i do indeed! i had the same problem only a couple of months ago. I'll try to find the code, but in the meantime check out my post with checkbox in the title!
×
×
  • 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.