Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating next and previous button

Status
Not open for further replies.

azamatali

Programmer
Aug 20, 2001
50
IN
hi folks,
i am trying to create next and previous button along with the links of the page numbers....
although the page number links are working fine but the next and the previous button are not working as required..
Help me out with this..
The code is..

<?php
// database connection stuff here
$db = mysql_connect(&quot;localhost&quot;, &quot;vivek&quot;, &quot;tarun150&quot;)
or die (&quot;Could not connect&quot;);
//print (&quot;Connected successfully&quot;);
mysql_select_db (&quot;vivek&quot;)
or die (&quot;Could not select database&quot;);


$rows_per_page = 30;
$sql = &quot;SELECT * FROM pat where cc='au'&quot;;
$result = mysql_query($sql, $db);
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);
print &quot;$pages&quot;;

if (!isset($screen))
$screen = 0;
$start = $screen * $rows_per_page;
$sql = &quot;SELECT tl FROM pat where cc='au' &quot;;
$sql .= &quot;LIMIT $start, $rows_per_page&quot;;
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
for ($i = 0; $i < $rows; $i++) {
$description = mysql_result($result, $i, 0);
echo &quot;\$description = $description<br>\n&quot;;
}
echo &quot;<p><hr></p>\n&quot;;

// let's create the dynamic links now
*********************************this does'nt work**********
if ($screen > 0) {

$url = &quot;example.php?screen=&quot; . $screen - 1;
echo &quot;<a href=\&quot;$url\&quot;>Previous</a>\n&quot;;
}
*********************************this does'nt work**********

// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = &quot;example.php?screen=&quot; . $i;
echo &quot; | <a href=\&quot;$url\&quot;>$i</a> | &quot;;
}

*********************************this does'nt work**********
if ($screen < $pages) {

$url = &quot;example.php?screen=&quot; . $screen + 1;
echo &quot;<a href=\&quot;$url\&quot;>Next</a>\n&quot;;
}
*********************************this does'nt work**********
?>
 
This will only help you out.

$results (number of rows in the search)

$totpages=($results % $rows_per_page == 0) ? ($results / $rows_per_page) : (floor($results / $rows_per_page+1);

$actual_page (the page i'm seeing)
mysql_data_seek($rows_per_page*($actual_page-1));

then read $rows_per_page records or till no more records.

I hope this can help you out. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top