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

  • SEARCH
  • Home
  • 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 695941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:00:42+00:00 2026-05-14T03:00:42+00:00

My table is posting and in that table, it shows all the posting people

  • 0

My table is posting and in that table, it shows all the posting people put in.
I am trying to make page navigation links at the bottom of the posts.
the function generateenter code here_page_links does all the work.

The code seem to be only showing the “<-” and “->” and not the link numbers. I think the function is only reading the $_GET[‘posting’] ==1.

(this code is from the Oreilly PHP/MySQL book. I am using it as practice)

function generate_page_links($cur_page, $num_pages) {
    $page_links = '';

    // If this page is not the first page, generate the "previous" link
    if ($cur_page > 1) { //cur_page is just a number that is gotten from the url.
      $page_links .= '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($cur_page - 1) . '"><--</a> ';
    }
    else {
      $page_links .= '<- ';
    }

    // Loop through the pages generating the page number links
    for ($i = 1; $i <= $num_pages; $i++) {
      if ($cur_page == $i) {
        $page_links .= ' ' . $i;
      }
      else {
         $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $i . '"> ' . $i . '</a>';
      }
    }

    // If this page is not the last page, generate the "next" link
    if ($cur_page < $num_pages) {
      $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($cur_page + 1) . '">-></a>';
    }
    if ($cur_page == $num_pages){ //the last page
      $page_links .= ' ->';
    }

    return $page_links; //need to return this variable in the function
  }

  // Calculate pagination information
  $cur_page = isset($_GET['page']) ? $_GET['page'] : 1;
  $results_per_page = 3;  // number of results per page
  $skip = (($cur_page - 1) * $results_per_page);


  $query = "SELECT * FROM posting ORDER BY date_added DESC";
  $data = mysqli_query($dbc, $query);
  $total = mysqli_num_rows($data);
  $num_pages = ceil($total / $results_per_page);

  //Query again to get just the subset of results
  $query =  $query . " LIMIT $skip, $results_per_page";
  $result = mysqli_query($dbc, $query);
  echo '<table>';
    echo '<tr><td><b>Title</b></td><td><b>Date Posted</b></td></tr>';
  while ($row = mysqli_fetch_array($result)) {
      echo '<tr><td><a href="ad.php? 

    posting_id='.$row['posting_id'].'

    ">'.$row['title'].'</a></td>';
    echo '<td>'.$row['date_added'].'</td>';
    //echo '<td>'.$row['name'].'</td></tr>';
  }
 echo '</table>';

  // Generate navigational page links if we have more than one page
  if ($num_pages > 1) {
    echo generate_page_links($user_search, $sort, $cur_page, $num_pages);
  }
  • 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-14T03:00:43+00:00Added an answer on May 14, 2026 at 3:00 am

    Well you have some problems here to start with:

    You call the function with 4 variables

    echo generate_page_links($user_search, $sort, $cur_page, $num_pages);
    

    But the function only accepts two

    function generate_page_links($cur_page, $num_pages)
    

    If that’s the code you’re using, then it’s probably going to crash because those variables are undefined.

    Try deleting “$user_search, $sort,” and see if that fixes it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small form inside a table. POSTing that form creates a new
I have a view that basically just returns all records from a table, and
I've been researching all over for this, basically I have a table that displays
I have page that creates a table: http://gupii.co.uk/rap/weekTable.php and I'm using a plugin to
A table exists that someone else loaded. I need to query against the table,
I am aware that this is somewhat a re-post, but I feel like re-posting
This web application is about posting different kind of posts to the web application
I have a script that appends some rows to a table. One of the
I have the following table: CREATE TABLE posting ( id integer NOT NULL PRIMARY
Before posting this question, I have tried so many things but that was not

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.