Forum Moderators: coopster

Message Too Old, No Replies

Archive problems

Anyway to use the same function twice?

         

skeddy

6:31 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



I'm in a spot of bother with the following piece of code.


$result = mysql_query("SELECT FROM_UNIXTIME( date, '%m%y' ) AS get_year , COUNT(*) AS entries FROM news WHERE publish='Yes' GROUP BY get_year ORDER BY id DESC");

while ($row = mysql_fetch_array($result)){

$get_year = $row["get_year"];
$entries = $row["entries"];

echo "<a href=\"main.php?content=archive_list&id=$get_year\">$get_year</a> ($entries)<br />";
}

This lists all my blog entries like this following:

1005 (1)
0405 (1)
0305 (12)
0205 (17)

I'd ideally like the link to stay the same, [localhost...] but have the text displayed as the actual month and year.

So it looks more like

October 2005 (1)
April 2004 (1)
March 2005 (12)
February 2005 (17)

Can anyone advise me on how to achive this?

ergophobe

7:18 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



UNIXTIME(date, '%M %Y')

should do it

skeddy

7:32 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



Thanks fot that, but I think I may have been unclear as to what I want to do.

In the last part, it echos out the $get_year twice.

It's the second $get_year that I wish to change to a proper month, whilst leasvig the first one as the 2 digit month and year.

skeddy

7:58 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



Resolved!


<?php
$result = mysql_query("SELECT FROM_UNIXTIME(date, '%m%y' ) AS get_year , FROM_UNIXTIME(date, '%M %Y' ) AS get_month, COUNT(*) AS entries FROM news WHERE publish='Yes' GROUP BY get_year ORDER BY id DESC");
while ($row = mysql_fetch_array($result)){
$get_year = $row["get_year"];
$get_month = $row["get_month"];
$entries = $row["entries"];
echo "<a href=\"main.php?content=archive_list&id=$get_year\">$get_month</a> ($entries)<br />";
}
?>

ergophobe

11:25 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can also just use the PHP date() function and format any way you want.