multiple pages and code not working

Hi,
   I need some help with a page which has many links.... on my main page I have a textbox which allows a keyword to be entered, this keyword is then checked in the database and all matching entries returned.  On the bottom of the page I have:

Page 1, Page 2, Page3

All has links to another page.

I use this code to submit the details and return the values:

if(isset($_GET['submit'])){

echo "This is a test";

}

The way i call the other pages is via:

mypage.php?page=2
or
mypage.php?page=3
etc.

However when the other pages are called the test wording in the

if(isset($_GET['submit'])){

echo "This is a test";

}

Isn't displayed, which I believe is due to the submit button not being pressed, so on the subsequent pages, it never gets triggered.  What I would like to know is how can I get round this issue, so on the subsequent pages either all the data is passed, or the submit routine is triggered?

Thanks
damianb123Asked:
Who is Participating?
 
Ali KayahanFull Stack DeveloperCommented:
Can you please try to modify dynamically generated links like ;

"<a href=\"$targetpage?page=1&miles=$miles&submit=true\">1</a>
0
 
Ali KayahanFull Stack DeveloperCommented:
I am not that sure i got you clearly . But if you are trying to pass your keyword which you got on your first page via text box you should somehow pass it to other pages. You may use ;

mypage.php?page=2&submit=mykeyword ;

and change $_GET to

if(isset($_REQUEST('submit'))){
  echo "bla bla bla" ;
}

so you can pass your data to subsequent pages.
0
 
damianb123Author Commented:
Hi,
    What it is I am trying to do is configure pagination on a page, within the page this occurs:

if(isset($_GET['submit'])){

echo "This is a test";

$miles = $_GET['miles'];
$miles_latlon = 0.00020882756 * $miles * $miles; //Approx Value
$user_longitude = $_SESSION['longitude'];
$user_latitude = $_SESSION['latitude'];

if ($user_longitude == "") {
$user_longitude = '-1.7220088';
}

if ($user_latitude == "") {
$user_latitude = '52.8834706';
}

      $tbl_name="members";            //your table name
      $adjacents = 5;
      
      $rows1 = mysql_query( "SELECT * FROM members WHERE ((longitude-".$user_longitude.")*(longitude-".$user_longitude.")+(latitude-".$user_latitude.")*(latitude-".$user_latitude."))<".($miles_latlon)." AND accounttype='Employer' AND visible='1'" )
or die("SELECT Error: ".mysql_error());

$num_rows1 = mysql_num_rows($rows1);      
      
      $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE ((longitude-".$user_longitude.")*(longitude-".$user_longitude.")+(latitude-".$user_latitude.")*(latitude-".$user_latitude."))<".($miles_latlon)." AND accounttype='Employer' AND visible='1'";
      $total_pages = mysql_fetch_array(mysql_query($query));
      $total_pages = $total_pages[num];
      
      /* Setup vars for query. */
      $targetpage = "clientzone.php";       //your file name  (the name of this file)
      $limit = 5;                                                 //how many items to show per page
      $page = $_GET['page'];
      if($page)
            $start = ($page - 1) * $limit;                   //first item to display on this page
      else
            $start = 0;                                                //if no page var is given, set start to 0
      
      /* Get data. */
      $sql = "SELECT * FROM $tbl_name WHERE ((longitude-".$user_longitude.")*(longitude-".$user_longitude.")+(latitude-".$user_latitude.")*(latitude-".$user_latitude."))<".($miles_latlon)." AND accounttype='Employer' AND visible='1' ORDER BY RAND() LIMIT $start, $limit";
      $result = mysql_query($sql);
      
      /* Setup page vars for display. */
      if ($page == 0) $page = 1;                              //if no page var is given, default to 1.
      $prev = $page - 1;                                          //previous page is page - 1
      $next = $page + 1;                                          //next page is page + 1
      $lastpage = ceil($total_pages/$limit);            //lastpage is = total pages / items per page, rounded up.
      $lpm1 = $lastpage - 1;                                    //last page minus 1
      
      /*
            Now we apply our rules and draw the pagination object.
            We're actually saving the code to a variable in case we want to draw it more than once.
      */
      $pagination1 = "";
      if($lastpage > 1)
      {      
            $pagination1 .= "<div class=\"pagination1\">";
            //previous button
            if ($page > 1)
                  $pagination1.= "<a href=\"$targetpage?page=$prev\">« previous </a>";
            else
                  $pagination1.= "<span class=\"disabled\">« previous </span>";      
            
            //pages      
            if ($lastpage < 7 + ($adjacents * 2))      //not enough pages to bother breaking it up
            {      
                  for ($counter = 1; $counter <= $lastpage; $counter++)
                  {
                        if ($counter == $page)
                              $pagination1.= "<span class=\"current\">$counter</span>";
                        else
                              $pagination1.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                              
                  }
            }
            elseif($lastpage > 5 + ($adjacents * 2))      //enough pages to hide some
            {
                  //close to beginning; only hide later pages
                  if($page < 1 + ($adjacents * 2))            
                  {
                        for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                        {
                              if ($counter == $page)
                                    $pagination1.= "<span class=\"current\">$counter</span>";
                              else
                                    $pagination1.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                              
                        }
                        $pagination1.= "...";
                        $pagination1.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                        $pagination1.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";            
                  }
                  //in middle; hide some front and some back
                  elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
                  {
                        $pagination1.= "<a href=\"$targetpage?page=1\">1</a>";
                        $pagination1.= "<a href=\"$targetpage?page=2\">2</a>";
                        $pagination1.= "...";
                        for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                        {
                              if ($counter == $page)
                                    $pagination1.= "<span class=\"current\">$counter</span>";
                              else
                                    $pagination1.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                              
                        }
                        $pagination1.= "...";
                        $pagination1.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                        $pagination1.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";            
                  }
                  //close to end; only hide early pages
                  else
                  {
                        $pagination1.= "<a href=\"$targetpage?page=1\">1</a>";
                        $pagination1.= "<a href=\"$targetpage?page=2\">2</a>";
                        $pagination1.= "...";
                        for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                        {
                              if ($counter == $page)
                                    $pagination1.= "<span class=\"current\">$counter</span>";
                              else
                                    $pagination1.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                              
                        }
                  }
            }
            
            //next button
            if ($page < $counter - 1)
                  $pagination1.= "<a href=\"$targetpage?page=$next\"> next »</a>";
            else
                  $pagination1.= "<span class=\"disabled\"> next »</span>";
            $pagination1.= "</div>\n";            
      }
}

Which basically gets all the resultsm works out how many there are, displays 5 per page and then adds links to subsequent pages, now the link generated dynamically for each page is:

clientzone.php?page=2

but when you go to page 2 it displays nothing, not even the test echo right at the start.....  so it's not executing if(isset($_GET['submit'])){, so nothing inside gets returned.  If I remove the if(isset($_GET['submit'])){ it works great.

How can I overcome this? I hope this clears up any confusion.  

Damian
0
 
damianb123Author Commented:
Thanks very much, that is exactly what I needed.  Great help, points well earned.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.