Jump to content

php problem (Selecting data from database)


JonnySnip3r

Recommended Posts

Hey guys im making a blog and when i make a post it automatically takes the date and created an archive based on what ever i have in the database (date wise) anyways it works almost fine but if i make a date in the same month it duplicates like so:

 

October 2010

October 2010

November 2010

 

Is there away where i can limit October by 1 but when i come to make a post next year it will still display like so:

 

October 2010

November 2010

December 2010

January 2011

...

October 2011

 

If i show you the code might make more sense haha::

 

public function create_archive()
{
	// Loop through the database grabbing all the dates::
	$sql = "SELECT blog_date
			FROM subarc_blog";

	$stmt = $this->conn->prepare($sql);
	$stmt->execute();
	$stmt->bind_result($date);

	$rows = array();

	while($row = $stmt->fetch())
	{
		$date = explode("-",$date);
		$month = date("F",mktime(0,0,0,$date['1']));
		$year = $date[0];

		$item = array(
			'blog_month' => $month,
			'blog_year' => $year
		);
		$rows[] = $item;
	}
	$stmt->close();
	return $rows;
}

 

and the sidebar looks like so::

 

<ul class="sidebar">
	<?php
	$result = $Database->create_archive();
	foreach($result as $row) : 
	?>
	<li><a href=""><?php echo $row['blog_month'] . " " . $row['blog_year']; ?></a></li>
	<?php endforeach; ?>
</ul>

 

Hope someone can help!

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.