/    Sign up×
Community /Pin to ProfileBookmark

another date related issue

how would i go about setting in the bottom loop for getting each year in the database from the timestamps and looping though each month of the year

eg.
2005 dec
2006 jan
2006 feb
etc…

i would also possibly like to have it only start from the first month a date was entered but it may require more work than its worth

[code=php]
//knowj blog
//08/08/06
//multipage display

//define the months matching there numeric order
$month[1] = “January”;
$month[2] = “February”;
$month[3] = “March”;
$month[4] = “April”;
$month[5] = “May”;
$month[6] = “June”;
$month[7] = “July”;
$month[8] = “August”;
$month[9] = “September”;
$month[10] = “October”;
$month[11] = “November”;
$month[12] = “December”;

//set current date into an array in numeric form
$date[day] = date(dmy);
$date[month] = date(m);
$date[year] = date(Y);

$query = “SELECT DATE_FORMAT(`blog_date`, ‘%Y’) FROM `kj_blog` ORDER BY `id` DESC”;
$result = mysql_query($query) or die(mysql_error());
$i = 1;
echo “<ul>”;
while ($row = mysql_fetch_assoc($result))
{
while ($i<=$date[month])
{
//here i want to have for each year in the database echo every month with year into a list
echo ‘<li><a href=”?id=1&amp;bmonth=’.$i.’&amp;byear=’.$row[year].'”>’ .$month[$i].’ ‘.$date[year].'</a></li>’;
$i++;
}
}
echo “</ul>”;
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@themartyAug 09.2006 — [url=http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html]date & time functions[/url]

[code=php]
$query = "SELECT DATE_FORMAT(blog_date, '%Y %M') AS blog_date_str FROM kj_blog GROUP BY blog_date_str ORDER BY blog_date";
if ($result = mysql_query($query))
{
echo "<ul>n";
while ($row = mysql_fetch_assoc($result))
echo " <li>".$row['blog_date_str']."</li>n";
echo "</ul>n";
}
else
{
echo $query."<br>n".mysql_error();
}
[/code]
×

Success!

Help @knowj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...