Bopo Posted April 19, 2009 Share Posted April 19, 2009 Hi Well basically I have build a archive category for months, (e.g. jan, feb, mar display in navigation, when clicked articles within jan for example are listed), everything was going great, however I decided to limit the amount of articles to 5 per page, and I started writing code to do this, until I spotted a BIG flaw in what I'm doing, basically I'm retrieving everything, because using dates within queries never, ever works for me, therefore I decided to do the work manually, however doing this approach I can't limit the amount of articles for e.g. jan because I'm retrieving everything and if I used the LIMIT clause and set it to 5 for example, it would retrieve 5 articles but none of these might not be jan, so that's not practical either. <?php $month = $_GET['month']; $year = $_GET['year']; $pageno = $_GET['page']; $one = 1; $page = ($one + $pageno); include("admin/blogconnect.php"); $sql = "SELECT * FROM blogposts ORDER BY id DESC"; $query = mysql_query($sql, $connect); while ($row = mysql_fetch_assoc($query)) { $breakdate = explode(" ", date('F, Y',strtotime($row['date']))); $removecomma = substr($breakdate[0], 0, -1); $storemonth = $removecomma; $storeyear = $breakdate[1]; if($storemonth == $month && $storeyear == $year) { print '<div id="articleblock"><a href="viewpost.php?postid=' . $row['id'] . '">' . '<h1 class="frontpageheader">' . $row['title'] . '</h1></a>'; // error due to h2 tags // echo $row['id'].'<br />'; echo '<p class="author_date">' . '<em>Posted By</em>' . '<span class="author"> ' . $row['author'].'</span> <em> On </em>' . date('F d, Y',strtotime($row['date'])) . '</p>'; $countcharacters = (strlen($row['post'])); if($countcharacters >= 450) { $trimpost = substr($row['post'],0,450); echo '<p>' . $trimpost . '...' . '<a href="viewpost.php?postid=' . $row['id'] . '">' . $moreinfo . '</a></p></div>'; } else { $trimpost = substr($row['post'],0,399); echo '<p>' . $trimpost . '</p></div>'; } } } echo'<a href="archive.php?month=' . $row['month'] . '&year=' . $row['year'] . '&page=' . $page . '">' . 'Next' . '</a>'; ?> Does anyone have any idea what I can do with this, if you can produce a query using dates that works ill use it, but I have had 2 threads on here about dates within queries, and none have worked. Link to comment https://forums.phpfreaks.com/topic/154775-solved-retriving-select-amount-of-records/ Share on other sites More sharing options...
The Little Guy Posted April 19, 2009 Share Posted April 19, 2009 I think I have the perfect piece of code for you! http://beta.phpsnips.com/snippet.php?id=94 Link to comment https://forums.phpfreaks.com/topic/154775-solved-retriving-select-amount-of-records/#findComment-814051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.