Jump to content

[SOLVED] Order by month


timmah1

Recommended Posts

I have this page that lists newsletters grouped by year, and the months listed.

The months are entered in like this

'January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December')

 

How can I order these correctly with the names?

I can't change the way the form is inputted or I would, would make this easier.

 

I just need it to order the month's correctly, instead of alphabetically

 

This is what I have

$archived = mysql_query("SELECT * FROM newsletter WHERE year = '$year''");

echo "<ul>";
while($n1 = mysql_fetch_array($archived)){
echo "<li><a href=newsletter.php?id=$n1[newsID]>$n1[month]</a></li>";

}
echo "</ul>";

 

Right now it lists them in order alphabetically

 

Can anybody help me out?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/140178-solved-order-by-month/
Share on other sites

This is what I did, and it is working

The only flaw is, it's showing 3 listings for December 2008, even though there is only one listing for that month and year

<?php
$archived = mysql_query("SELECT * FROM newsletter WHERE year = '$year'");
echo "<ul>";

$packages = array("January"=>'',"February"=>'',"March"=>'',"April"=>'',"May"=>'',"June"=>'',"July"=>'',"August"=>'',"September"=>'',"October"=>'',"November"=>'',"December"=>'');

while($t = mysql_fetch_array($archived)){
$packages[$t['month']] =  $t['newsID'];
}

foreach ($packages as $f => $v) 

if($v == "") {
	$fn = "";
}
else {

if($f == "January") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "February") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "March") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "April") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "May") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "June") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "July") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "August") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "September") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "October") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "November") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}
if($f == "December") {
	$fn = "<a href='newsletter.php?id=$v'>$f</a>";
}

echo "<li>$fn</li>";
}

echo "</ul>";
}
?>

 

I'm sure it's something simple

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.