ayaya Posted February 11, 2013 Share Posted February 11, 2013 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']; } ?> Link to comment https://forums.phpfreaks.com/topic/274360-phpmysql-display-data-and-split-on-pages/ Share on other sites More sharing options...
ayaya Posted February 11, 2013 Author Share Posted February 11, 2013 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! Link to comment https://forums.phpfreaks.com/topic/274360-phpmysql-display-data-and-split-on-pages/#findComment-1411839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.