JonnySnip3r Posted November 1, 2010 Share Posted November 1, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/217461-php-problem-selecting-data-from-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2010 Share Posted November 1, 2010 Untested, but should work - $sql = "SELECT DISTINCT MONTHNAME(blog_date) as blog_month, YEAR(blog_date) as blog_year FROM subarc_blog ORDER BY blog_date"; Quote Link to comment https://forums.phpfreaks.com/topic/217461-php-problem-selecting-data-from-database/#findComment-1129023 Share on other sites More sharing options...
JonnySnip3r Posted November 1, 2010 Author Share Posted November 1, 2010 Thanks very much for the fast response dude will give it ago Quote Link to comment https://forums.phpfreaks.com/topic/217461-php-problem-selecting-data-from-database/#findComment-1129025 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.