nextpage help needed!

Started on the old forum in June 2006 · view the original in the archive · old links redirect here

6 replies · 641 views · started 20 years ago · 1 min read

2 participants
naveen-PHP LEARNER #1

I need help in making nextpage with PHP.... When i retrieve data from MySQL , I know to show limited number of rows but i need to show the other in next page. 5rows per page.

Example , when a page is viewed , 5rows are shown and 5 in the next page and so on.

Please help me...if possible explain it. External image (may be gone)

Thanks. External image (may be gone)

mobix #2
<?php

//  Of course connect your mysql first :)  //

//get in what page are you
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}

$max_results = 5;//you can change how much row's show in page
$to = ($page * $max_results) - $max_results;
$form = $to - $max_result;
  
$sql = mysql_query("SELECT * FROM `some_table` LIMIT $to, $max_results");
      
while($row=mysql_fetch_array($sql)){
//printing your data
}

$page_sql = mysql_query("SELECT * FROM `some_table`");
$total_results = mysql_num_rows($page_sql);//how much rows are in table
$total_pages = ceil($total_results / $max_results);

//go back if it need
if($page > 1){
$prev = ($page - 1);
print '[url="some.php?page='.$prev.'"]Back[/url]
';
}

//go to next page if that exist
if($page < $total_pages){
$next = ($page + 1);
print '[url="some.php?page='.$next.'"]Next[/url]
';
}

?>

Sorry but my english is not so well to comment it more ... i hope it will help you External image (may be gone)

naveen-PHP LEARNER #3
<?php

//  Of course connect your mysql first :)  //

//get in what page are you
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}

$max_results = 5;//you can change how much row's show in page
$to = ($page * $max_results) - $max_results;
$form = $to - $max_result;
  
$sql = mysql_query("SELECT * FROM `some_table` LIMIT $to, $max_results");
      
while($row=mysql_fetch_array($sql)){
//printing your data
}

$page_sql = mysql_query("SELECT * FROM `some_table`");
$total_results = mysql_num_rows($page_sql);//how much rows are in table
$total_pages = ceil($total_results / $max_results);

//go back if it need
if($page > 1){
$prev = ($page - 1);
print 'Back
';
}

//go to next page if that exist
if($page < $total_pages){
$next = ($page + 1);
print 'Next
';
}

?>

Sorry but my english is not so well to comment it more ... i hope it will help you External image (may be gone)

Thanks mate!! External image (may be gone) External image (may be gone) External image (may be gone)

stretch Developer · 130 posts #5

how do one create a next page option in a php file when you have links to files stored on another server?

3gpfiles.php

<?
echo "<a href=\"http://filestore.com/mobile/files/file1.3gp\">file1.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file2.3gp\">file2.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file3.3gp\">file3.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file4.3gp\">file4.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file5.3gp\">file5.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file6.3gp\">file6.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file7.3gp\">file7.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file8.3gp\">file8.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file9.3gp\">file9.3gp</a>
";
echo "<a href=\"http://filestore.com/mobile/files/file10.3gp\">file10.3gp</a>
";
?>

how do put the code in to show 5 links per page? and what should the code look like?

$prev_page = $page -1;
echo "
<a href=\"3gpfiles.php."?page=$prev_page\">Prev</a>
";
$next_page = $page + 1;
echo "
<a href=\"3gpfiles.php."?page=$next_page\">Next</a>
";

External image (may be gone)

= = = = = The more you laugh...the longer you live. Read more jokes at http://fun-files.co.cc

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close