Hi, I created some sort of a blog feature on my website, I only show the lastest post. But I want to make it posible to browse into the earlier posts by using the PHP pageing… But when I go to next page I get the same result as a do in the first page… Why?
Heres my code:
if(isset($_GET["loginid"]))
{
// Check if user exists in the database
$username = $_GET["loginid"];
require_once("functions/DbConnector.php");
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM login WHERE username='$username'";
$result = $db->query($query);
$exists = mysql_num_rows($result); // Does the row exists?
$getsql = mysql_query($query);
while($loginDB = mysql_fetch_array($getsql))
$picture = $loginDB['profpicture'];
if (isLoggedIn() ) {
?>
<div id="firstBar">
<fieldset>
<legend><h3><?php echo $username; ?>'s Picture</h3></legend>
<a href="<?php echo $picture; ?>" rel="lightbox" title="<?php echo $username; ?>'s profile picture."><img src="<?php echo $picture; ?>" width="200" height="200" /></a>
<?php
if($exists !="0"){ // Presentation exists so display it
$rows = $db->fetchArray($result); // Get the profile from database
$present = $rows["presentation"];
$present = htmlspecialchars($present);
$present = nl2br($present);
if($_GET["loginid"]!=$_SESSION[username])
{
echo "<a href=\"member.php?add=".$_GET["loginid"]."\"><h4>[Add ".$_GET["loginid"]." to your friends]</h4></a>";
};
echo $present; ?></fieldset></div>
<div id="secondBar">
<?php
$noEntriesQuery = mysql_query ("SELECT postid FROM blog WHERE poster='$username'") or die(mysql_error());
$noEntries = mysql_num_rows($noEntriesQuery);
$pageLimit = 1;
$noPages = ceil($noEntries / $pageLimit);
$currentPage = 0;
$start = $currentPage * $pageLimit;
$view_blog = "SELECT * FROM blog WHERE poster = '$username' ORDER BY postid DESC LIMIT ".$start.",".$pageLimit;
$sqlblogg = mysql_query($view_blog);
if(!$sqlblogg)
{
?>
<p><?php print '$sqlblogg: '.$sqlblogg.mysql_error();?></p>
<?php
}
if(isset($_GET['page']) &&
is_numeric($_GET['page']) &&
$_GET['page'] > 0 &&
$_GET['page'] < $noPages){
$currentPage = $_GET['page'];
}
while($blogg = mysql_fetch_array($sqlblogg)) {
$poster = $blogg['poster'];
$posttitle = $blogg['posttitle'];
$blogpost = $blogg['blogpost'];
$timeposted = $blogg['timeposted'];
}
?>
<fieldset>
<legend><h3><?php echo $username; ?>'s Blog</h3></legend>
<table width="100%">
<tr> <?php
if (!mysql_num_rows($sqlblogg) )
{ echo "This user has no posts yet. "; } else {
?>
<td width="35px"><p><u>Title:</u></p></td>
<td width=""><p><?php echo $posttitle; ?></p></td>
</tr>
<tr>
<td width="35px"><p><u>On</u></p></td>
<td width=""><p><?php echo $timeposted; ?></p></td>
</tr>
</table>
<table width="100%">
<td width="300px"><hr></br><?php echo nl2br($blogpost); ?></td>
<?php }
if($a < $noPages - 1){
echo 'Previous posts: ';
for($a = 0; $a < $noPages; $a++){
if($currentPage == $a){
echo($a+1);
}else{
echo '<a href="'.$_SERVER['PHP_SELF'].'?loginid='.$username.'&page='.$a.'">'.($a+1).'</a>';
}
if($a < $noPages - 1){
echo '-';
}
}
} ?>
</table>
</fieldset>
</div>
<?php
}
else
{
echo "This member does not exist";
}
}
else {
show_loginform();
}
}
Thanks