mamay
08-15-2004, 05:21 AM
I've got a db that has some fileds like 'product_id' ,'sell_date',..
there is a page in my program that user can enter a year number and submit the page to see all the days in that year
that a product is selled with the number of sell in that special day.
I could do this with a query for each day (I mean 365 queries) in tow for loops,one for month and anothe for day:
<?
for($month=1;$month<=12;$month++)
for($day=1;$day<=31;$day++)
{
$res = mysql_query("Select count(*) From mytable Where sell_date='$year-$month-$day'",$handle)
if( $data = mysql_fetch_array($res) )
echo $year."-".$month."-".$day.":".$data[0];
.....
}
?>
but it will take a long time to do 365 queries!
Is there another way that I can do this task with just one query?
Thanks in advance.
there is a page in my program that user can enter a year number and submit the page to see all the days in that year
that a product is selled with the number of sell in that special day.
I could do this with a query for each day (I mean 365 queries) in tow for loops,one for month and anothe for day:
<?
for($month=1;$month<=12;$month++)
for($day=1;$day<=31;$day++)
{
$res = mysql_query("Select count(*) From mytable Where sell_date='$year-$month-$day'",$handle)
if( $data = mysql_fetch_array($res) )
echo $year."-".$month."-".$day.":".$data[0];
.....
}
?>
but it will take a long time to do 365 queries!
Is there another way that I can do this task with just one query?
Thanks in advance.