Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.