Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Array query

Status
Not open for further replies.

PDT

Programmer
May 19, 2001
40
AU
Having trouble getting this query to work, returns a null set from MySQL database, also any help on how to return array in quarters rather than 12 months would be appreciated,
Thanks

$month=1;

while ($month<13) {
$result= mysql_query(&quot;SELECT * FROM Events WHERE type='Movie' and date like '2002-$month-'&quot;);
$num_rows = mysql_num_rows($result);

echo $num_rows.&quot;,&quot;.$month.&quot;<br>&quot;;
$month++;
}
?>


Output should be either in format (12 months):

1,19,15,7,22,14,5,9,21,13,7,35

Or alternatively listed:

0,1
0,2
0,3
0,4
0,5
0,6
0,7
0,8
0,9
0,10
0,11
0,12
 
Use the MySQL quarter() function:

[tt]
Code:
$resource = mysql_query(&quot;SELECT quarter(date) as quarter, count(id) as count FROM Events WHERE type='Movie' and year(date) = 2002 group by quarter(date)&quot;);

print &quot;<html><body><pre>&quot;;

while ($result = mysql_fetch_array($resource, MYSQL_ASSOC))
{
	print $result['quarter'].&quot;\t&quot;.$result['count'].&quot;\n&quot;;
}

print &quot;</pre></body></html>&quot;;
[/tt] ______________________________________________________________________
TANSTAAFL!
 
Thankyou for this, will give it a try, could anyone point out why original code returned a null set just for my learning?
Cheers
 
Your LIKE search term doesn't include the day. You would have to add __ to the end, so it would be '2002-$month-__'. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top