Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:37:57+00:00 2026-05-27T06:37:57+00:00

$objConnect = mysql_connect(localhost,root,) or die(mysql_error()); $objDB = mysql_select_db(Test); $strSQL = SELECT * FROM UserAddedRecord

  • 0
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("Test");

$strSQL = "SELECT * FROM UserAddedRecord WHERE (Name LIKE '%".$getname."%' and State LIKE '%".$getstate."%' and Cell LIKE '%".$getcell."%' and Custgroup LIKE '%".$getgroup."%') AND user_id=$id";

$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);

$Per_Page = 5;   

if (!isset($_GET['Page'])) {
    $Page = 1;
} else {
    $Page = $_GET['Page'];
}

$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;

$Page_Start = (($Per_Page * $Page) - $Per_Page);
if ($Num_Rows <= $Per_Page) {
    $Num_Pages = 1;
} elseif (($Num_Rows % $Per_Page) == 0) {
    $Num_Pages = ($Num_Rows / $Per_Page) ;
} else {
    $Num_Pages = ($Num_Rows / $Per_Page) + 1;
    $Num_Pages = (int) $Num_Pages;
}


$strSQL .=" order  by addedrec_ID DESC LIMIT $Page_Start , $Per_Page";
$objQuery  = mysql_query($strSQL) or trigger_error(mysql_error());;

if ($Prev_Page) {
    echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'><< Back</a> ";
}

for ($i=1; $i <= $Num_Pages; $i++) {
    if ($i != $Page) {
        echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$i&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'>$i</a> ";
    } else {
        echo "<b> $i </b>"; 
    }
}

if ($Page!=$Num_Pages) {
    echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'>Next>></a> ";        
}

mysql_close($objConnect);

This is the code I use to create pagination page for data search.But I just noticed that I have too many records then it will have too many page numbers.I’m trying to limit the page number shown,and look for many examples ..it have many ways to do it but I still don’t have idea how to limit it for my method…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:37:58+00:00Added an answer on May 27, 2026 at 6:37 am

    Ok if you mean show something like

    Prev 1 2 3 4 5 6 .. 40 41 Next 
    Prev 1 2 .. 6 7 8 9 10 .. 40 41 Next
    

    First thing we need to is create a function that can process what we need to output the pagination. Heres a function I use and it works well.

    function get_paging_info($tot_rows,$pp,$curr_page)
    {
        $pages = ceil($tot_rows / $pp); // calc pages
    
        $data = array(); // start out array
        $data['si']        = ($curr_page * $pp) - $pp; // what row to start at
        $data['pages']     = $pages;                   // add the pages
        $data['curr_page'] = $curr_page;               // Whats the current page
    
        return $data; //return the paging data
    
    }
    

    Now this function is pretty solid and works very well for me.

    So you pass this function

    • $tot_rows = counted rows for query
    • $pp = items per page
    • $curr_page = the current page number

    Ok, now that you have the data you need, you’ll need to display it.

    Heres what I use and please read it before you think, ‘ah, it’s too long’. It’s actually very simple.

    Heres a snapshot of what it will return

    enter image description here

        <!-- Create the query -->
        <?php $count = mysql_fetch_assoc( mysql_query ( "SELECT COUNT( rows ) as count FROM table" ) ) ;
    
        <?php $count = $count[0]['count']; ?>
    
    <!-- Call our function from above -->
    <?php $paging_info = get_paging_info($count,5,34); ?>
    
    
    <p>
        <!-- If the current page is more than 1, show the First and Previous links -->
        <?php if($paging_info['curr_page'] > 1) : ?>
            <a href='' title='Page 1'>First</a>
            <a href='' title='Page <?php echo ($paging_info['curr_page'] - 1); ?>'>Prev</a>
        <?php endif; ?>
    
    
    
        <?php
            //setup starting point
    
            //$max is equal to number of links shown
            $max = 7;
            if($paging_info['curr_page'] < $max)
                $sp = 1;
            elseif($paging_info['curr_page'] >= ($paging_info['pages'] - floor($max / 2)) )
                $sp = $paging_info['pages'] - $max + 1;
            elseif($paging_info['curr_page'] >= $max)
                $sp = $paging_info['curr_page']  - floor($max/2);
        ?>
    
        <!-- If the current page >= $max then show link to 1st page -->
        <?php if($paging_info['curr_page'] >= $max) : ?>
    
            <a href='' title='Page 1'>1</a>
            ..
    
        <?php endif; ?>
    
        <!-- Loop though max number of pages shown and show links either side equal to $max / 2 -->
        <?php for($i = $sp; $i <= ($sp + $max -1);$i++) : ?>
    
            <?php
                if($i > $paging_info['pages'])
                    continue;
            ?>
    
            <?php if($paging_info['curr_page'] == $i) : ?>
    
                <span class='bold'><?php echo $i; ?></span>
    
            <?php else : ?>
    
                <a href='' title='Page <?php echo $i; ?>'><?php echo $i; ?></a>
    
            <?php endif; ?>
    
        <?php endfor; ?>
    
    
        <!-- If the current page is less than say the last page minus $max pages divided by 2-->
        <?php if($paging_info['curr_page'] < ($paging_info['pages'] - floor($max / 2))) : ?>
    
            ..
            <a href='' title='Page <?php echo $paging_info['pages']; ?>'><?php echo $paging_info['pages']; ?></a>
    
        <?php endif; ?>
    
        <!-- Show last two pages if we're not near them -->
        <?php if($paging_info['curr_page'] < $paging_info['pages']) : ?>
    
            <a href='<?php echo str_replace('/page'.$paging_info['curr_page'], '', $paging_info['curr_url']) . '/page'.($paging_info['curr_page'] + 1); ?>' title='Page <?php echo ($paging_info['curr_page'] + 1); ?>'>Next</a>
    
            <a href='<?php echo str_replace('/page'.$paging_info['curr_page'], '', $paging_info['curr_url']) . '/page'.$paging_info['pages']; ?>' title='Page <?php echo $paging_info['pages']; ?>'>Last</a>
    
        <?php endif; ?>
    </p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php $objConnect = mysql_connect(localhost,,root) or die(mysql_error()); $objDB = mysql_select_db(mydb); $pic2 = SELECT * FROM
I am testing an XML-RPC set up in node.js and would like to test
i am trying to send a picture from 'C:\picture.bmp' to 'c:\temp\picture.bmp' using server and
I am trying to create a basic console app in order to stress test
With functionality from the RODBC package, I have successfully created an ODBC but receive
Dear all, I am using java rmi for my program, from client side i
I am trying to send some text from the client's end to the server.
I have to call a previously created function on SQL, like SET @ExtVALUE =
Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, boolean given in select This
I'm uploading a csv from a form. I'm trying to use mysql_affected_rows to determine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.