Jump to content

[SOLVED] Retriving Select Amount of Records


Bopo

Recommended Posts

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.

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.