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!

Link to comment
Share on other sites

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.