Re: too many records

From: Date: Thu, 15 Jun 2000 01:21:45 +0000
Subject: Re: too many records
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-423@lists.php.net to get a copy of this message
That's not a very efficient way to do it. Let the database do the work for you. You can loop through: select * from verbscom where YEAR(date)=2000 and MONTH(date)=$i Or, you could probably even do it all in a single query by using a group by month(date) clause. -Rasmus > > I am working with a database that has two fields, an IP and a > date. This is a snippet of the data, > > +-----------------+---------------------+ > | 63.91.195.171 | 2000-04-22 17:08:09 | > | 64.14.95.137 | 2000-04-27 01:57:07 | > | 64.20.27.92 | 2000-04-06 16:20:09 | > +-----------------+---------------------+ > > What I wnat to do is select all the records from a certian month, I wrote > a for loop that looks like this. > > for ($i = 0; $i < 12; $i++) > { > $next_month = $i + 2; > $month_query = > "SELECT * FROM verbscom WHERE date > '2000-$i-31' > and date < '2000-$next_month-00'"; > $month_total = mysql_query($month_query); > $total_hits_month = mysql_num_rows($month_total); > $month = $i + 1; > echo( TR ); > echo( TD . "Total hits for this month" . $month . ":" . CLOSE_TD ); > echo( TD . $total_hits_month . CLOSE_TD ); > echo( CLOSE_TR ); > } > > Now, it seems to work fine except for if I do SELECT * FROM verbscom I get > a few more rows than if I add the totals from the 12 querys this loop > executes. If anyone has a better idea of how I might want to approach this > subject I would be willing to give it a shot. As far as I can tell this > loop should do the trick. But I am a little confused > > Thanks > Ken N > > > > http://cleveland.lug.net/~rocket/ > > The answer is simple if you grant that ironies are like submarines; > dangerous only when submerged. > > > >

« previous php.db (#423) next »