?
Solved

multiple pages and code not working

Posted on 2011-05-08
4
Medium Priority
?
224 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:damianb123
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Ali Kayahan
ID: 35715144
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
 

Author Comment

by:damianb123
ID: 35715161
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
 
LVL 14

Accepted Solution

by:
Ali Kayahan earned 2000 total points
ID: 35715172
Can you please try to modify dynamically generated links like ;

"<a href=\"$targetpage?page=1&miles=$miles&submit=true\">1</a>
0
 

Author Closing Comment

by:damianb123
ID: 35715270
Thanks very much, that is exactly what I needed.  Great help, points well earned.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question