simplify in declaring variables value in php
- by Robert John Concepcion
$jan5 = 0;
$feb5 = 0;
$mar5 = 0;
$apr5 = 0;
$may5 = 0;
$jun5 = 0;
$jul5 = 0;
$aug5 = 0;
$sep5 = 0;
$oct5 = 0;
$nov5 = 0;
$dec5 = 0;
$jan4 = 0;
$feb4 = 0;
$mar4 = 0;
$apr4 = 0;
$may4 = 0;
$jun4 = 0;
$jul4 = 0;
$aug4 = 0;
$sep4 = 0;
$oct4 = 0;
$nov4 = 0;
$dec4 = 0;
$jan3 = 0;
$feb3 = 0;
$mar3 = 0;
$apr3 = 0;
$may3 = 0;
$jun3 = 0;
$jul3 = 0;
$aug3 = 0;
$sep3 = 0;
$oct3 = 0;
$nov3 = 0;
$dec3 = 0;
this is the most time consuming code when i try to make for example i want the default value of $jan5 is equal to zero.. can some one teach me how to make this short? thank you so much for reading
$date = 'smi_initialdate';
$level = 'smi_level';
$year = '2012';
$result1 = mysql_query("SELECT *, DATE_FORMAT( $date, '%m' ) As monthz FROM eis_mngt_sales_iti WHERE year($date) = '$year' ORDER BY $date");
while($row=mysql_fetch_array($result1))
{
$count++;
if($row['smi_level']=='5star')
{
if($row['monthz']==1)
{
$jan++;
}elseif($row['monthz']==2)
{
$feb++;
}elseif($row['monthz']==3)
{
$mar++;
}elseif($row['monthz']==4)
{
$apr++;
}elseif($row['monthz']==5)
{
$may++;
}elseif($row['monthz']==6)
{
$jun++;
}elseif($row['monthz']==7)
{
$jul++;
}elseif($row['monthz']==8)
{
$aug++;
}elseif($row['monthz']==9)
{
$sep++;
}elseif($row['monthz']==10)
{
$oct++;
}elseif($row['monthz']==11)
{
$nov++;
}elseif($row['monthz']==12)
{
$dec++;
}
}
}
i decide to put this $jan5 = 0;$feb5 = 0;$mar5 = 0;$apr5 = 0;$may5 = 0;$jun5 = 0;$jul5 = 0; so that if the data did not pass to this condition if($row['smi_level']=='5star') they have the return value of zero(0).
so that my output can adapt in this code
[<?php echo$jan5.",".$feb5.",".$mar5.",".$apr5.",".$may5.",".$jun5.",".$jul5.",".$aug5.",".$sep5.",".$oct5.",".$nov5.",".$dec5;
?]
if a dont use the above code the $jan5 = 0;$feb5 = 0;$mar5 = 0;$apr5 = 0;$may5 = 0;$jun5 = 0;$jul5 = 0;................ when i echo or print it i look like this
1,2,5,11,12 but with the use of that(the first sample code above) the output will be 1,0,0,0,0,0,0,1,2,5,11,12.
thank, sorry if this became confusing, sorry about my grammar