tags:

views:

42

answers:

3

I have a php code that fetches data from mysql. The data has (say) 15 rows. I want to display only 5 rows at a time to the user, with links to each of the set (3 in this case) such that when a user clicks on either of the links, the same page will show the corresponding results. Since, php code has the final result set, I don't want a solution that involves me to navigate to other pages and possibly re-calculate the next set of solutions (5~10 or 10~15). How can I do this? Thanks in advance.

If I am using javascript or ajax, how can I achieve this? I don't know javascript much.

+1  A: 

You can try loading everything in your page and simulating the pagination thanks to javascript.

An example in jQuery here

Chouchenos
+1  A: 

It sounds like you want to send the Data as a complete set to the client but not let him display everything to the user. So use Javascript to just show you the pages 1*page_number to 5*page_number (with a for-loop).

erikb
can you tell me how can I achieve this?
Repeat the following until you can write the appropriate code yourself: Do a Javascript/Ajax Tutorial.Seriously, more help you can not expect. If you have any problems with your concrete try to implement that, you can ask here. We will help you. But I don't think, I should implement a program for you (without proper payment). Sorry.
erikb
A: 

By far, the easiest solution in this situation is a Dom-based Grid system. I recommend checking out Datatables. In essence, the Datatables code will take a fully-formatted html table and reformat it to include only the amount of rows you tell it to, with paging on the bottom as you've requested. In addition, you can turn on such features as filtering, toggle-able length, sorting, and selection. Once you get the hang of it, the additional code takes no more than a minute per table and the features are outstanding.

This is really straightforward. Use PHP to output ALL of the table, with all the rows. The only gotcha here is to include the full html, including <thead> and <tbody> Give the table an id such as "example"

Now, include the files that you download from the datatables site--datatables.js and Jquery.js. Instantiate the jquery like this:

$(document).ready(function() {
    $('#example').dataTable();
} );

That's it. As you can see from the examples, it's a really cool tool. Good luck.

bpeterson76