Sorting db entries by Year-Month

From: Date: Tue, 23 Jul 2002 23:26:19 +0000
Subject: Sorting db entries by Year-Month
Groups: php.general 
Request: Send a blank email to php-general+get-109168@lists.php.net to get a copy of this message
Apache 1.3.23 + PHP 4.1.2 + PostgreSQl 7.2 I have a guestbook that I would like to display the current month's entries. I can display all the entries before the current month, but i can't seem to figure out how to extract the currrent month's. Although the code below is a db issue, I don't know whether I should write code to extract the info before or after the db connection. Should I: 1. Set up the parameters beforehand in PHP, and then do a query; 2. Within the query itself (as the code I tried [and didn't work] below); 3. Or, somehow in PHP, after I get all the results [obviously without the db WHERE clause]. <?php // lots of code $db = pg_connect("dbname=rap user=postgres"); $query = "SELECT * FROM guest WHERE pdate = "{$_SESSION['pdate'] == date('Y-m')"; // pdate is formatted ('Y-m-d') // etc, etc. . . ?> I know this is a simple question -- but my mind's totally blotto after a day's coding. Any help, pointers of where to look, or admonitions will be gratefully accepted. Tia, Andre

« previous php.general (#109168) next »