开发者

PHP Pagination script doesn't work [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

The pagination script I use doesn't display the posts for some reason. It displays nothing, no previous link, no next link, no actual things from the mysql database. The page is not a white screen, everything else on the page works fine. It would be great if someone could help me with this.

<?php
session_start();
include "config.php";
if($_SESSION['usrid']){
database_connect();
$sql = 'SELECT id FROM posts limit '.($page*$eachPage).','.$eachPage;

$sql_count = 'SELECT id FROM posts';
                if(isset($_GET['page']) AND ctype_digit($_GET['page'])) {

    $page = $_GET['page'];    
}
else{

    $page = 0;    
}

if(!$res = mysql_query($sql)) {

  trigger_error(mysql_error().'<br />In query: '.$sql); 
} 
elseif(mysql_num_rows($res) == 0) { 

  echo 'No posts found'; 
} 
else { 

  while($row = mysql_fetch_assoc($res)) { 
  $posttime = date("F j \a\t g:i a", strtotime ( $row [ 'time' ] ));
      ?>
      <div class="t"><p id="i"><?php echo $row['post']; ?><br /><b class="oinf">By <a href="profile.php?id=<?php echo $row['id']; ?>" class="od"> on <?php echo $posttime; ?></a></b></p></div><br /><br />
    <?php
  }

  if开发者_Go百科($res = mysql_query($sql_count)) {

      $results = mysql_num_rows($res);
    }
  $pages = ceil($results / $eachPage);

  if($page > 0) {

      echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($page-1).'">[Previous]</a>';
  }
  else{

      echo '[Previous]';
  }

  for($i = 1; $i <= $pages; $i++)    {

      echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($i-1).'">'.$i.'</a>';
    } 

  if(($page+1) <= ($results/$eachPage)) {

      echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($page+1).'">[Next]</a>';
  }
  else{

      echo '[Next]';
  }
}

            }else{

            };?>

Edit: I know tried to use this code for debugging, but it gives me the same result as above, it does not display the posts:

if($_SESSION['usrid']){
    database_connect();
    $navquery = "SELECT * from posts";
$navresult = mysql_query($navquery) or die(mysql_error());  
while ($row = mysql_fetch_assoc($navresult)) {
    ?>
    <div class="t"><p id="i"><?php echo $row['post']; ?><br /><b class="oinf">By <a href="profile.php?id=<?php echo $row['id']; ?>" class="od"> on <?php echo $row['time']; ?></a></b></p></div><br /><br />
    <?php
};
};


I got it to work, I forgot a }.


Echo out this SQL query and find out why your script isn't working.

$sql = 'SELECT id FROM posts limit '.($page*$eachPage).','.$eachPage;

Returns:

SELECT id FROM posts limit ,

Since $page and $eachPage are not defined. Are those supposed to come from $_GET? Because someone could actually just do this:

/mypage?page=0&eachPage=;DELETE FROM posts;

And you're not doing anything to prevent that from happening.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜