AaronC Posted October 30, 2009 Share Posted October 30, 2009 $year = $_GET['year']; if (empty($year)) { echo "Enter A Year";} else { echo "<b>Posts</b><br />"; $jan = 0; $feb = 0; $march = 0; $april = 0; $may = 0; $june = 0; $july = 0; $aug = 0; $sept = 0; $oct = 0; $nov = 0; $dec = 0; $query = $db->simple_select("posts", "*"); while($post = $db->fetch_array($query)) { $date = date("m",$post["dateline"]); $postyear = date("Y",$post["dateline"]); if ( !$postyear==$year ) { if ( $date == "1" ) { $jan++;} if ( $date == "2" ) { $feb++;} if ( $date == "3" ) { $march++;} if ( $date == "4" ) { $april++;} if ( $date == "5" ) { $may++;} if ( $date == "6" ) { $june++;} if ( $date == "7" ) { $july++;} if ( $date == "8" ) { $aug++;} if ( $date == "9" ) { $sept++;} if ( $date == "10" ) { $oct++;} if ( $date == "11" ) { $nov++;} if ( $date == "12" ) { $dec++;} } } echo "January (".$jan." posts)<br />"; echo "February (".$feb." posts)<br />"; echo "March (".$march." posts)<br />"; echo "April (".$april." posts)<br />"; echo "May (".$may." posts)<br />"; echo "June (".$june." posts)<br />"; echo "July (".$july." posts)<br />"; echo "August (".$aug." posts)<br />"; echo "September (".$sept." posts)<br />"; echo "October (".$oct." posts)<br />"; echo "November (".$nov." posts)<br />"; echo "December (".$dec." posts)"; echo "<p></p>"; } Doesnt seem to be working, any ideas why? Link to comment https://forums.phpfreaks.com/topic/179623-if-problems/ Share on other sites More sharing options...
KevinM1 Posted October 30, 2009 Share Posted October 30, 2009 We're not telepathic. 'Not working' is hardly descriptive of the problem, and you have multiple if-conditionals. What precisely is the problem, and which 'if' is the cause? Link to comment https://forums.phpfreaks.com/topic/179623-if-problems/#findComment-947789 Share on other sites More sharing options...
Mark Baker Posted October 30, 2009 Share Posted October 30, 2009 $date = date("m",$post["dateline"]); returns a numeric representation of a month (note that this is actually a string), with leading zeros if ( $date == "1" ) { $jan++;} gives if ("01" == "1").... comparing string with string, they aren't the same And why not use an array for this $monthArray = array(1,12,0); $query = $db->simple_select("posts", "*"); while($post = $db->fetch_array($query)) { $date = date("n",$post["dateline"]); $postyear = date("Y",$post["dateline"]); if ( !$postyear==$year ) { $monthArray[$date]++; } } foreach($monthArray as $month => $count) { echo date("M",mktime(0,0,0,$month,1,2009))." (".$count." posts)<br />"; } Link to comment https://forums.phpfreaks.com/topic/179623-if-problems/#findComment-947796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.