Re: Date operations.

From: Date: Wed, 30 Jan 2002 00:57:32 +0000
Subject: Re: Date operations.
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-16290@lists.php.net to get a copy of this message
Garry, Could you please explain (define) in one sentence(paragraph) what end result you want. It might be possible to handle it in one SQL statement. Miles Thompson At 09:54 AM 1/30/2002 +1100, Garry Optland wrote:
On Wed, 30 Jan 2002, DL Neil wrote: Can I request some db-speak please? You already have a tbl (or more). So let's start by asking for the table definitions The table definition is as follows: CREATE TABLE breeding ( rec SMALLINT(4) UNSIGNED AUTO_INCREMENT, sire SMALLINT(4) UNSIGNED, dam SMALLINT(4) UNSIGNED, paired DATE, split DATE, num_offspring TINYINT(1) ZEROFILL, PRIMARY KEY (rec) ); Do you already have some SQL as a 'first attempt'? Could you also post that, together with a note about its short-comings/what needs to be added? That would also assist (my, feeble) comprehension. First, we define if a pair was breeding for a given date by seeing if that date lies between the paired date and the split date. In mysql: SELECT FROM breeding WHERE TO_DAYS(paired) <= TO_DAYS('$given_date') AND TO_DAYS('$given_date') <= TO_DAYS(split); Where it gets messy is this has to be put into a loop, between the given start and end dates (year and month only). For each day in the loop, I have to do a query and count the number returned to php. Then average that figure for the month. Normally start and end dates would be input via a form. I was wondering if anyone had done that sort of thing, or whether there was a more efficient way of doing it than stepping through the database one day at a time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.db (#16290) next »