-1

This is my code:

$query="SELECT * from project where batch='$bach'" or die(mysql_error());  
$var=mysql_query($query) or die(mysql_error());  
if(mysql_num_rows($var)==0)  
{  
  echo "No such batch exist.<br />";  
}

        while($arr=mysql_fetch_row($var))
        {
            echo $arr['batch'];


        }

I am just displaying one field right now thats batch but there are 8 columns and many rows would be filled when user inputs the data.. This code will display the content on the same page making the page quite long. How can i split the data into various pages with html and php? A better example can be google which splits the search results into pages and with page numbers at the bottom.

shet_tayyy
  • 5,366
  • 11
  • 44
  • 82
  • 1
    Have a look at this question http://stackoverflow.com/questions/109232/what-is-the-best-way-to-paginate-results-in-sql-server and http://stackoverflow.com/questions/17159313/mysql-query-with-php-pagination – ButterDog May 03 '14 at 15:44
  • 1
    you could use limit in php – Dev Man May 03 '14 at 15:45
  • Paging or paginating.. Thats the word actually i was looking for and not for any code.. Thanks a lot – shet_tayyy May 03 '14 at 17:53

2 Answers2

1

Please chk this tutorial for php mysql pagination http://www.tutorialspoint.com/php/mysql_paging_php.htm .

dhi_m
  • 1,235
  • 12
  • 21
0

I would personally recommend two things for you. Create a router that will take a variable from url , like yoursite/list/11 , it will create a list , with eleventh set of your database values. Use mod_rewrite so you can have "pretty urls" About PHP routing

You will need to create a function that will count your DB entries , and divide that number into page sets. Say One hundred entries equals ten pages. This will let you create that kind of menu that looks like 1,2,3....,9,10.

Another function which will retrieve the specific set of entries, and then pass it to whatever script runs your "list"

Since your question is not 'help me find error' but rather 'how to achieve this', I'm afraid I cannot offer more than basic logic of things.

Second thing i will recommend is avoiding mysql_ functions , because these are deprecated and will be removed from PHP.

Slytherin
  • 474
  • 3
  • 17
  • @Slytherine Its a bit complicated since i am a novice but I'll try to understand.. Thanks for your help and time. – shet_tayyy May 03 '14 at 17:57