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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:25:07+00:00 2026-06-13T16:25:07+00:00

I know this is a common problem as I have searched for answers before

  • 0

I know this is a common problem as I have searched for answers before deciding to post, but I can’t seem to figure out a solution.

PROBLEM: I have a pagination script (PHP) to use for my search results. As is apparently common, the first page results show fine, then fail when moving onto page 2, 3 etc.

I get an ‘unknown index’ error for each of my variables used in the search when clicking through to page 2, 3 etc.

So I $_GET these variables from my form:

$_SESSION['var1']= $_GET['var1'];
$_SESSION['var2']= $_GET['var2'];
$_SESSION['var3']= $_GET['var3'];

Points to note:
A Session has already been started in my header; I’m using $_GET because i prefer not having the ‘resubmit’ warning if a user goes ‘back’; variables are all cleaned (just not shown in code as its long enough already); I have to use the $_GET variables with the WHILE loop as they calculate distance, age etc of each result.

My pagination script:

$limit = 4; 

$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

$stages = 3;
$page = mysql_escape_string(isset($_GET['page'])) ? (int)$_GET['page'] : 1;
if($page) {
  $start = ($page - 1) * $limit; 
} else {
  $start = 0;   
}   

// Get page data
$query1 = "SELECT * FROM $tableName ORDER BY joindate DESC LIMIT $start, $limit";
$result = mysql_query($query1);

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;  
$next = $page + 1;                          
$lastpage = ceil($total_pages/$limit);      
$LastPagem1 = $lastpage - 1;                    

$paginate = '';
if($lastpage > 1) {
$paginate .= "<div class = 'hp1col'><div class='paginate'>";
$pagetotal = $total_pages.' Results';

// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>Previous</a>";
} else {
$paginate.= "<span class='disabled'>previous</span>";}

// Pages    
if ($lastpage < 7 + ($stages * 2))  // Not enough pages to breaking it up
{   
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                 
}
}

// Next
if ($page < $counter - 1){ 
$paginate.= "<a href='$targetpage?page=$next'>Next</a>";
} else {
$paginate.= "<span class='disabled'>Next</span>";
}
$paginate.= "</div></div>";     
}

while($row = mysql_fetch_array($result))
{
if (($part1 >= $_SESSION['var1']) AND  ($part2 <= $_SESSION['var2']) AND ($part3 <= $_SESSION['var3'])) {
echo 
"[Results]  
}
}
echo $paginate;

I tried starting a new session in this if statement but it didn’t help:

if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>Previous</a>";
} else {
$paginate.= "<span class='disabled'>previous</span>";}

I hope someone can help. I apologise for the slab of code in the question, but I thought it best just to put everything in for ease in, hopefully, someone being able to help.

Thanks

  • 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-06-13T16:25:09+00:00Added an answer on June 13, 2026 at 4:25 pm

    So you need to pass those query parameters through to the next page. If your page expects $_GET['var1'] to be present but you don’t have ?var1=foo in the URL, it obviously won’t work. The easiest way to handle this is http_build_query:

    printf('<a href="%s?%s">Next</a>',
           $targetpage,
           http_build_query(array('page' => 2) + $_GET));
    

    This preserves all current values in $_GET and adds a page=2 parameter to it. Modify as needed for your case.

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

Sidebar

Related Questions

I know this is a common problem but I can't seem to find a
I know this is a common problem but I have stared, read googled and
I know this has been a very common and existing problem, but I have
Know this might be rather basic, but I been trying to figure out how
So I know this is a common problem and have seen a lot of
I know this is a common problem with IE6 from my Google search but
I know this must be a pretty common problem, but I haven't been able
I know this is the most common problem in the history of programming but
I don't know if it's a common problem, but I can't find the solution
I know this is a pretty common problem but any of the solutions I

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.