Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2007, 01:04 AM
Registered User
 
Join Date: Mar 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Navigating through the data in MySQL

Hi all,

Can Someone please help me in navigating through the data present in database table on a form by using " NEXT " & " PREVIOUS " buttons using JSP.



                             Id : 009
                        Name : Abc
                Percentage : 81


                 << PREVIOUS NEXT >>


this is the structure.

Thanks in advance,
Prad.
 
Old March 22nd, 2007, 10:07 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Prad,
First you need to know the total no of rows in your Select query in your example:

$con = mysqli_connect($host, $username, $password, $databasename);

$sql = "SELECT * FROM tablename";

$rst = $con->query($sql);

$num_rows = $rst->num_rows;

// Assuming you want to show 3 record ins a page:
$offset = 0;
$limit = 3

SELECT Id, Name, Percentage
FROM tablename
LIMIT $offset, $limit;

// create a script to show your example here:

// Your footer:
// Create the 'previous' link
if ($offset > 0) {
   $prev = $offset - $limit;;
   $url = $_SERVER['PHP_SELF']."?offset=$prev";
   echo "<a href=\"$url\">Previous</a> ";
}

// Create the 'next' link
if ($offset < ($num_rows-$limit)) {
   $next = $offset + $limit;
   $url = $_SERVER['PHP_SELF']."?offset=$next";
   echo "<a href=\"$url\">Next</a>";
}

enjoy




 
Old March 23rd, 2007, 12:27 AM
Registered User
 
Join Date: Mar 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jmaronilla,

    Thanks for your help, your code really helped me a lot. I have one more problem, Can u give me some more help in doing the same application using Java Server Pages.
Thanks in advance,
Prad.

 
Old March 23rd, 2007, 12:44 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Prad,
Sorry, I don't know Java Server Pages.

 
Old March 23rd, 2007, 01:58 AM
Registered User
 
Join Date: Mar 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jmaronilla,
  No problem, anyway thank you very much.

Prad






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in navigating kk2ka4 XSLT 1 November 12th, 2008 01:45 AM
Navigating through the data in MySQL prad_a JSP Basics 1 March 23rd, 2007 07:48 AM
Navigating data in a subform Bob Pierce Access VBA 2 February 1st, 2007 10:58 AM
Navigating Recordsets w/out specifying name Tethys Access VBA 7 December 5th, 2005 04:47 PM
navigating a dataset ranakdinesh BOOK: Professional C#, 2nd and 3rd Editions 4 June 1st, 2004 11:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.