Jump to content

Recommended Posts

I have 10 rows of data in mysql, i want to display 5 rows of data per page in PHP. I can display 5 rows in page 1, but the page 0 (precedent page), and next page (page 2), don't work. Can anyone help me? This is my code:

<?php
include ("conn.php");

$pagesize=5;
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url['path']; 

$numq=mysql_query("select * from `test`");
$num=mysql_num_rows($numq);

$page='';
$pageval=0;
if(isset($_GET['page'])){
 $pageval=$_GET['page'];
 $page=($pageval-1)*$pagesize;
 $page.=',';
}

if($num > $pagesize){
 if($pageval<=1)$pageval=1;
 echo "$num in total".
 " <a href=$url?page=".($pageval-1).">Page precedent</a> <a href=$url?page=".($pageval+1).">Next page</a>";
}

$sql="select * from `test` limit $page $pagesize";
$query=mysql_query($sql);

while($row=mysql_fetch_array($query)){
 echo "<hr><b>".$row['name']." | ".$row['sex'];
}

?>

come to update...

 

for the above code, my url is: http://localhost/bbs2/list.php

if i add ?page=2 behind the url, that means: http://localhost/bbs2/list.php?page=2

it works, it can show the next 5 rows of data.

but only if i click the Next page on the page list.php, it doesn't work, it shows an alert page "This program cannot display the webpage.. " and if my mouse just rolls over on the text Next page, it can shows the right url on the bottom of firefox. so why it doesn't work when I click?

 

I was stuck on this problem since two days, can anyone help me? thanks a lot!

Edited by ayaya
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.