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 6175023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:51:10+00:00 2026-05-23T23:51:10+00:00

I am trying to do pagination using javascript but all in vain, please help..

  • 0

I am trying to do pagination using javascript but all in vain, please help..

<script language="Javascript">
function nextclicked()
{ 
document.getElementById("clickednext").value = document.getElementById("clickednext").value + 1;
document.forms["newsmanager"].submit();
}
</script>

<form name = "newsmanager" method="post" action="NewsManager.php">
<input type = "hidden"  id="clickednext" name="clickednext" > 


if(isset($_POST['clickednext']) && $_POST['clickednext']>=1)
{    
$_POST['clickednext'] = $_POST['clickednext'] +9; 
$NewsQuery = "SELECT NewsDetails FROM News LIMIT " .$_POST['clickednext']. ",10";
    }
    else
    {
    $NewsQuery  = "SELECT NewsDetails FROM News LIMIT 0,10";
    }

    $result = mysqli_query($dbc,$NewsQuery);
}

UPDATE :

     <div class=d2 align=left>
<a  href="#" onclick=" nextclicked(); submit();" >
Next
</a>

UPDATE ENDS……

The first time when i click the Next hyperlink label, then it works, that is, 10 is assigned $_POST[‘clickednext’] and the next 10 values appear from the database, but the second time i click the label , then it doesn’t?

  • 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-23T23:51:11+00:00Added an answer on May 23, 2026 at 11:51 pm

    Here’s a little algorithm I wrote using php to create pagination:

    $x=$numStories;
    $y=$x%5;
    $z=($x-$y)/5;
    if($y!=0){
        $numPages=$z+1;
    }
    else{
        $numPages=$z;
    }
    

    Where 5 is the number of stories per page, and $numStories is the total amount of stories (or in your case, news articles) you wish to use.

    Then, just display the amount of pages ($numPages) in any way you’d like, and your good to go.

    [EDIT]

    I created an archive.php page, that took a page number as a GET parameter (archive.php?page=3). From there, I selected the first five entries in my database after $pageNum (in this case 3) * 10 (or however many posts per page you are wanting to display.

    The best thing to do is make as much of your code dynamic and flexible, so that it is self sustaining.

    [EDIT 2]

    <script>
    function nextclicked()
    { 
        document.forms["newsmanager"].submit();
    }
    </script>
    
    <?php
        $currentPage = $_POST['page'];
    
        $numStories = //get the total amount of entries
        $x=$numStories;
        $y=$x%10;
        $z=($x-$y)/10;
        if($y!=0){
            $numPages=$z+1;
        }
        else{
            $numPages=$z;
        }
    
        if(isset($currentPage) && $currentPage>=1)
        {    
        $currentPage = $currentPage +9; 
        $NewsQuery = "SELECT NewsDetails FROM News LIMIT " .$currentPage. ",10";
            }
            else
            {
            $NewsQuery  = "SELECT NewsDetails FROM News LIMIT 0,10";
            }
    
            $result = mysqli_query($dbc,$NewsQuery);
        }
    
    ?>
    
    <form>
        <input type='hidden' name='page' text='' value='<?php echo "$currentPage"' />
    </form>
    <a href="#" onclick="nextClicked()">Next--></a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.