Jump to content

[SOLVED] Pagination address bar


graham23s

Recommended Posts

Hi Guys,

 

i have coded a pagination scripts which works well but after a user does a search this is in the addresss bar:

 

search.php?gender=0&herefor=0&country=0&fromage=1&toage=30&ethnicity=0&hair=0&build=0&eyes=0&search=Search

 

pagination links:

 

<?php
  ## Pagination Links
  echo ("<div id=\"pagination\" align=\"left\">");
  
	// Figure out the total number of pages. Always round up using ceil() 
	$totalpages = ceil($numresults / $perpage); 

	// Build Previous Link 
	if($page > 1){ 
		$prev = ($page - 1); 
		echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<< </a> "; 
	} 

	for($i = 1; $i <= $totalpages; $i++){ 
		if(($page) == $i){ 
			echo "[<b>$i</b>] "; 
			} else { 
				echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
		} 
	} 

	// Build Next Link 
	if($page < $totalpages){ 
		$next = ($page + 1); 
		echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"> >>></a>"; 
	} 

  echo ("</div>");	
?>

 

if i click the next page i get this in the adress bar:

 

search.php?page=1

 

and shows no results, my question is do i need to have all the variables in the address bar above and THEN page=2 etc after it to work?

 

thansk for any help guys

 

Graham

Link to comment
Share on other sites

Did you do this:

$gender = $_GET['gender'];

 

for all the variables? If you somehow extracted the value of these variables, they have to be put in like so:

 

<?php
$abb_bar = null;
if(isset($gender) || !empty($gender)){
$add_bar .= "&gender=$gender";
}

if(isset($herefor) || !empty($herefor)){
$add_bar .= "&herefor=$herefor";
}
//....
//....
//....
//....
//....
if(isset($eyes) || !empty($eyes)){
$add_bar .= "&eyes=$eyes";
}


  ## Pagination Links
  echo ("<div id=\"pagination\" align=\"left\">");
  
	// Figure out the total number of pages. Always round up using ceil() 
	$totalpages = ceil($numresults / $perpage); 

	// Build Previous Link 
	if($page > 1){ 
		$prev = ($page - 1); 
		echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$prev&$add_bar\"><<< </a> "; 
	} 

	for($i = 1; $i <= $totalpages; $i++){ 
		if(($page) == $i){ 
			echo "[<b>$i</b>] "; 
			} else { 
				echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&add_bar\">$i</a> "; 
		} 
	} 

	// Build Next Link 
	if($page < $totalpages){ 
		$next = ($page + 1); 
		echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&add_bar\"> >>></a>"; 
	} 

  echo ("</div>");	
?>

 

So all I have to do is compile the $add_bar variable with parts of the URL that are IN the url and they are not null, empty, blank, or 0. And use them in the next part of the search. (In order to fix the problem with some of them being zero, just add a simple check up top to set them to zero if it doesn't exist, etc...)

Link to comment
Share on other sites

Hi Mate,

 

yeah did that to my complete code is:

 

<?php  
     ## vars
     $fromage = range(1,99);
     $toage = range(1,99);
     $herefor = array("Acting","Modelling","Networking");
     $eyearray = array("Black","Blue","Brown","Grey","Green","Hazel");
     $hairarray = array("Auburn","Black","Blonde","Brown","Grey","Red","White","Multi-Colored");
     $buildarray = array("Athletic","Medium","Slim","Muscular","Large");
     $ethnicarray = array("African","African American","Asian/Pacific Islander","Caucasian","European","Hispanic","Indian","Middle Eastern","Native American","Asian","Mixed Race","Other Ethnicity");
     $countrylist = array("Afghanistan",
      		               "Albania",
      		               "Algeria",
      		               "Andorra",
      		               "Angola",
      		               "Antigua and Barbuda",
      		               "Argentina",
      		               "Armenia",
      		               "Australia",
      		               "Austria",
      		               "Azerbaijan",
      		               "Bahamas",
      		               "Bahrain",
      		               "Bangladesh",
      		               "Barbados",
      		               "Belarus",
      		               "Belgium",
      		               "Belize",
      		               "Benin",		
      		               "Bhutan",		
      		               "Bolivia",		
      		               "Bosnia and Herzegovina",		
      		               "Botswana",		
      		               "Brazil",		
      		               "Brunei",		
      		               "Bulgaria",		
      		               "Burkina Faso",		
      		               "Burundi",		
      		               "Cambodia",		
      		               "Cameroon",		
      		               "Canada",		
      		               "Cape Verde",		
      		               "Central African Republic",		
      		               "Chad",		
      		               "Chile",		
      		               "China",		
      		               "Colombi",		
      		               "Comoros",		
      		               "Congo (Brazzaville)",		
      		               "Congo",		
      		               "Costa Rica",		
      		               "Cote d'Ivoire",		
      		               "Croatia",		
      		               "Cuba",		
      		               "Cyprus",		
      		               "Czech Republic",		
      		               "Denmark",		
      		               "Djibouti",		
      		               "Dominica",		
      		               "Dominican Republic",		
      		               "East Timor (Timor Timur)",		
      		               "Ecuador",		
      		               "Egypt",		
      		               "El Salvador",	
      		               "England",
      		               "Equatorial Guinea",		
      		               "Eritrea",		
      		               "Estonia",		
      		               "Ethiopia",		
      		               "Fiji",		
      		               "Finland",		
      		               "France",		
      		               "Gabon",		
      		               "Gambia, The",		
      		               "Georgia",		
      		               "Germany",		
      		               "Ghana",		
      		               "Greece",		
      		               "Grenada",		
      		               "Guatemala",		
      		               "Guinea",		
      		               "Guinea-Bissau",		
      		               "Guyana",		
      		               "Haiti",		
      		               "Honduras",		
      		               "Hungary",		
      		               "Iceland",		
      		               "India",		
      		               "Indonesia",		
      		               "Iran",		
      		               "Iraq",		
      		               "Ireland",	
      		               "Israel",		
      		               "Italy",		
      		               "Jamaica",		
      		               "Japan",		
      		               "Jordan",		
      		               "Kazakhstan",		
      		               "Kenya",		
      		               "Kiribati",		
      		               "Korea, North",		
      		               "Korea, South",		
      		               "Kuwait",		
      		               "Kyrgyzstan",		
      		               "Laos",		
      		               "Latvia",		
      		               "Lebanon",		
      		               "Lesotho",		
      		               "Liberia",		
      		               "Libya",		
      		               "Liechtenstein",		
      		               "Lithuania",		
      		               "Luxembourg",		
      		               "Macedonia",		
      		               "Madagascar",		
      		               "Malawi",		
      		               "Malaysia",		
      		               "Maldives",		
      		               "Mali",		
      		               "Malta",		
      		               "Marshall Islands",		
      		               "Mauritania",		
      		               "Mauritius",		
      		               "Mexico",		
      		               "Micronesia",		
      		               "Moldova",		
      		               "Monaco",		
      		               "Mongolia",		
      		               "Morocco",		
      		               "Mozambique",		
      		               "Myanmar",		
      		               "Namibia",		
      		               "Nauru",		
      		               "Nepa",		
      		               "Netherlands",		
      		               "New Zealand",		
      		               "Nicaragua",		
      		               "Niger",		
      		               "Nigeria",		
      		               "Norway",		
      		               "Oman",		
      		               "Pakistan",		
      		               "Palau",		
      		               "Panama",		
      		               "Papua New Guinea",		
      		               "Paraguay",		
      		               "Peru",		
      		               "Philippines",		
      		               "Poland",		
      		               "Portugal",		
      		               "Qatar",		
      		               "Romania",		
      		               "Russia",		
      		               "Rwanda",		
      		               "Saint Kitts and Nevis",		
      		               "Saint Lucia",		
      		               "Saint Vincent",		
      		               "Samoa",		
      		               "San Marino",		
      		               "Sao Tome and Principe",		
      		               "Saudi Arabia",	
      		               "Scotland",
      		               "Senegal",		
      		               "Serbia and Montenegro",		
      		               "Seychelles",		
      		               "Sierra Leone",		
      		               "Singapore",		
      		               "Slovakia",		
      		               "Slovenia",		
      		               "Solomon Islands",		
      		               "Somalia",		
      		               "South Africa",		
      		               "Spain",		
      		               "Sri Lanka",		
      		               "Sudan",		
      		               "Suriname",		
      		               "Swaziland",		
      		               "Sweden",		
      		               "Switzerland",		
      		               "Syria",		
      		               "Taiwan",		
      		               "Tajikistan",		
      		               "Tanzania",		
      		               "Thailand",		
      		               "Togo",		
      		               "Tonga",		
      		               "Trinidad and Tobago",		
      		               "Tunisia",		
      		               "Turkey",		
      		               "Turkmenistan",		
      		               "Tuvalu",		
      		               "Uganda",		
      		               "Ukraine",		
      		               "United Arab Emirates",		
      		               "United Kingdom",		
      		               "United States",		
      		               "Uruguay",		
      		               "Uzbekistan",		
      		               "Vanuatu",		
      		               "Vatican City",		
      		               "Venezuela",		
      		               "Vietnam",		
      		               "Yemen",		
      		               "Zambia",		
      		               "Zimbabwe");
      		                		               
  echo ("<form action=\"search.php\" method=\"get\">");
  echo ("<table class=\"sub_table\" align=\"right\" width=\"300\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">");
  echo ("<tr>");
  echo ("<td colspan=\"2\" class=\"header_boxes\" align=\"left\"><span class=\"prof_head\">Search My Live Audition - [Full Search]</span></td>");
  echo ("</tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>I'm looking for a</b></td><td class=\"sub_table\" align=\"left\"><select name=\"gender\"><option value=\"0\">-- Search All --</option>");
  echo ("<option value=\"M\">Male</option><option value=\"F\">Female</option></select>");
  echo ("</td>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Who is here for</b></td><td class=\"sub_table\" align=\"left\"><select name=\"herefor\"><option value=\"0\">-- Search All --</option>");
  foreach($herefor as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>From</b></td><td class=\"sub_table\" align=\"left\"><select name=\"country\"><option value=\"0\">-- Search All --</option>");
  foreach($countrylist as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Min age</b></td><td class=\"sub_table\" align=\"left\"><select name=\"fromage\">");
  foreach($fromage as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Max age</b></td><td class=\"sub_table\" align=\"left\"><select name=\"toage\">");
  foreach($toage as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Ethnicity</b></td><td class=\"sub_table\" align=\"left\"><select name=\"ethnicity\"><option value=\"0\">-- Search All --</option>");
  foreach($ethnicarray as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Hair Color</b></td><td class=\"sub_table\" align=\"left\"><select name=\"hair\"><option value=\"0\">-- Search All --</option>");
  foreach($hairarray as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Build</b></td><td class=\"sub_table\" align=\"left\"><select name=\"build\"><option value=\"0\">-- Search All --</option>");
  foreach($buildarray as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"right\"><b>Eye Color</b></td><td class=\"sub_table\" align=\"left\"><select name=\"eyes\"><option value=\"0\">-- Search All --</option>");
  foreach($eyearray as $val) {
  echo ("<option value=\"$val\">$val</option>");
  }
  echo ("</select>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td colspan=\"2\" align=\"right\"><input type=\"submit\" class=\"btn\" name=\"search\" value=\"Search\" /></td>");
  echo ("</tr>");
  echo ("</table></form>");
  
  ## deal with the submission ###########################################################
  if(isset($_GET['search'])) { 
  
  ## vars we'll be using
   $gender = mysql_real_escape_string($_GET['gender']);
  $herefor = mysql_real_escape_string($_GET['herefor']);
  $country = mysql_real_escape_string($_GET['country']);
  $fromage = mysql_real_escape_string($_GET['fromage']);
    $toage = mysql_real_escape_string($_GET['toage']); 
$ethnicity = mysql_real_escape_string($_GET['ethnicity']);
     $hair = mysql_real_escape_string($_GET['hair']);
    $build = mysql_real_escape_string($_GET['build']);
     $eyes = mysql_real_escape_string($_GET['eyes']);
    
  ## Pagination
  $pagenumber = (isset($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1;
  
  ## results
  $perpage = 5;
  
  ## start index
  $from = (($pagenumber * $perpage) - $perpage);
        
  //======================== COMPILE QUERY ========================//
  $searchquery  = "SELECT * FROM `users` WHERE 1=1 ";
  
  ## GENDER #########################################################
  if(isset($gender) && ($gender != '0')) { 
  
  $searchquery .= "AND `gender`='$gender' "; 
  
  }
  ## HERE FOR #######################################################
  if(isset($herefor) && ($herefor != '0')) { 
  
  $searchquery .= "AND `herefor`='$herefor' "; 
  
  }  
  ## COUNTRY ########################################################
  if(isset($country) && ($country != '0')) { 
  
  $searchquery .= "AND `country`='$country' "; 
  
  }  
  ## ETHNICITY ######################################################
  if(isset($ethnicity) && ($ethnicity != '0')) { 
  
  $searchquery .= "AND `ethnic`='$ethnicity' "; 
  
  } 
  ## HAIR ###########################################################
  if(isset($hair) && ($hair != '0')) { 
  
  $searchquery .= "AND `hair`='$hair' "; 
  
  }  
  ## BUILD ##########################################################
  if(isset($build) && ($build != '0')) { 
  
  $searchquery .= "AND `build`='$build' "; 
  
  }    
  ## EYE_C ##########################################################
  if(isset($eyes) && ($eyes != '0')) { 
  
  $searchquery .= "AND `eye_c`='$eyes' "; 
  
  }     
  ## AGES ###########################################################
  $searchquery .= "AND `year` BETWEEN YEAR(CURDATE() - INTERVAL $toage YEAR) AND YEAR(CURDATE() - INTERVAL $fromage YEAR) LIMIT $from, $perpage";
  //======================== COMPILE QUERY ========================//
  
  ## run query
  $resultquery = mysql_query($searchquery);
  
  ## num results
  $numresults = mysql_num_rows($resultquery);
  
  ## no results
  if($numresults == 0) {

  echo ('<br /><span class="gallery_header">Sorry, no results were found!</span><br />');
  include("includes/footer.php");
  exit;
    
  } else {
   
  echo ('<br /><span class="gallery_header">We have found you <b>'.$numresults.'</b> matches!</span><br /><br />');
  
  while($row = mysql_fetch_array($resultquery)) {
  
  ## details
  $searchid = $row['id'];
  $searchusername = $row['username'];
  $searchthumb = $row['thumbnail'];
  
  $nopic = (!empty($searchthumb)) ? "<img src=\"thumbs/$searchthumb\">" : "<img src=\"images/noimgup.jpg\"";
   
  ## some results
  echo ("<table class=\"sub_table\" align=\"center\" width=\"300\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"center\">$nopic</td>");
  echo ("</tr>");
  echo ("</table>");
  echo ("<br />");  
  
  } // end while
  
  ## Pagination Links
  echo ("<div id=\"pagination\" align=\"left\">");
  
	// Figure out the total number of pages. Always round up using ceil() 
	$totalpages = ceil($numresults / $perpage); 

	// Build Previous Link 
	if($page > 1){ 
		$prev = ($page - 1); 
		echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<< </a> "; 
	} 

	for($i = 1; $i <= $totalpages; $i++){ 
		if(($page) == $i){ 
			echo "[<b>$i</b>] "; 
			} else { 
				echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
		} 
	} 

	// Build Next Link 
	if($page < $totalpages){ 
		$next = ($page + 1); 
		echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"> >>></a>"; 
	} 

  echo ("</div>");	
  
  }
  
  } // end if
  
?>

 

all the variables are getting through ok its just the pagination links really

 

Graham

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.