SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Perl And Next/Prev Page..

    Hi,

    Yep, me again..!
    I have a perl script that pulls info from a MySQL DB. It then displays the results on the page.
    However..
    Say the DB contains 1000 listings. I don't want a page that long! Does anyone know how to make it so that it only shows X results, then on the next page the next X, and so on?

    Here is the relevant code:

    Code:
    #**********************#
    # Get All Info From The DB #
    #***********************#
    $get_all_info = $dbh->prepare(qq(select * from info));
    $get_all_info->execute;
    while(($first_name,$last_name,$id,$email_address))= $get_all_info->fetchrow_array) {
    
    
    print<<ENDHTML;
    <tr>
    <td width="25%">$first_name</td>
    <td width="25%">$last_name</td>
    <td width="25%">$id</td>
    <td width="25%">$email_address</td>
    </tr>
    ENDHTML
    }
    Any help is GREATLY appreciated!

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can no one help me..?

    PLEASE...!

    Tx

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I don't know perl very well, but you will need to pass an offset to each page and then add the number of records you want to display on each page to it each time you load the page. Again I suck at perl but it might look something like this:

    Code:
    #**********************#
    # Get All Info From The DB #
    #***********************#
    $get_all = $dbh->prepare(qq(select count(*) as totalnum from info));
    $get_all->execute;
    if(!$offset) {
    	$offset = 0;
    	}
    $totalnum = $get_all->fetchrow_array;
    $numperpage = 20;
    
    $numpages = $totalnum / $numperpage;
    
    $get_all_info = $dbh->prepare(qq(select * from info LIMIT $offset, $numperpage));
    $get_all_info->execute;
    
    while(($first_name,$last_name,$id,$email_address))= $get_all_info->fetchrow_array) {
    
    
    print<<ENDHTML;
    <tr>
    <td width="25%">$first_name</td>
    <td width="25%">$last_name</td>
    <td width="25%">$id</td>
    <td width="25%">$email_address</td>
    </tr>
    ENDHTML
    }
    
    if($totalnum > $numperpage) {
    	for($i=0;$i<numpages;$i++) {
    		print<<ENDHTML;
    		<a href="scriptname.php?offset=$offset">$i</a> 
    		ENDHTML
    		}
    	}

    Again I suck at perl but this hopefully will give you an idea on how to proceed.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANK YOU!

    It is a very good start, but it'll need some work. I'll try my best to get it working right, but I might need some more help in the future.

    Thank you for the great coding!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •