Re: Simplified data processing

From: Date: Wed, 20 Dec 2000 18:12:08 +0000
Subject: Re: Simplified data processing
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31268@lists.php.net to get a copy of this message
Patrick: > $query=pg_exec($dbconn,"SELECT * FROM Schedule,Occurrence WHERE > Schedule.Scheduleid = Occurrence.Scheduleid AND OccurDate >= '$firstdow' > ORDER BY OccurDate, StartTime"); > $numrows=pg_numrows($query); > $row=pg_fetch_array($query,0); > $firstday=$row[occurdate]; //First date returned > $row=pg_fetch_array($query,$numrows-1); > $lastday=$row[occurdate]; //Last date returned I'm not familiar with Postgre, but I'll bet you can get the dates you want from the query itself: $query=pg_exec($dbconn,"SELECT MIN(occurdate) as firstdate, MAX(occurdate) as lastdate FROM Schedule,Occurrence WHERE Schedule.Scheduleid = Occurrence.Scheduleid AND OccurDate >= '$firstdow'"); Then extract the info you need. > //These dates are strings and must be now split up into separate values > $firstdate=explode("-",$firstday); > if (count($firstdate) != 3) > $firstdate=explode("/",$firstday); > $lastdate=explode("-",$lastday); > if (count($lastdate) != 3) > $lastdate=explode("/",$lastday); You mean the occurdate column isn't a date field?!?! Why not? You've got to change that. You may run into problems and take up more disk space. For example, "-" has a lower ASCII number than "/" so things may not sort correctly. Here's a quick test result from a MySQL database: 2000-2-27 2000-2-28 2000/1/28 2000/2/27 I suspect that's not quite what you're looking for. Also, it causes you to jump through hoops in your code, like you're doing above, having to explode on "-", check it and then potentialy explode on "/" Enjoy, --Dan -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#31268) next »