Neptunus Maris Posted September 12, 2007 Share Posted September 12, 2007 Hi guys I've built an advanced search engine with pagination. First: I did use all the tutorials on this site for pagination. Second: I did use all other resources. Here is the site: http://devel.ecountrylifestyle.com/green_thumb_gardener/resources/facilities.php?fac=A Here is the last update of the code: <?php //connect include('../../includes/PHP/globals_db.inc'); $dbconn = mysql_connect($ecl_database_server, $ecl_username, $ecl_password) or die(mysql_error()); $select = mysql_select_db($ecl_database, $dbconn) or die(mysql_error()); //------------ //first lets make an array of letters A-Z $alpha = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "Y", "Z"); $links_top = ""; foreach ($alpha as $links) { $links_top .= "<a class = \"checklist\" href = 'facilities.php?fac=$links'>"; if ($links == "Z") { $links_top .= "$links</a>"; } else { $links_top .= "$links</a> | "; } //end if } //end if //type array $fac_type = array("Type of Facility" => "None", "Arboretum" => "A", "Arboretum/Garden" => "A, G", "Garden" => "G", "Garden/Arboretum" => "G, A", "Park" => "P", "Park/Garden" => "P, G", "Garden/Park" => "G, P", "Conservatory" => "C"); //states $fac_state = array("State Select" => "State", "Alabama" => "AL", "Alaska" => "AL", "Arizona" => "AZ", "Arkansas" => "AK", "California" => "CA", "Colorado" => "CO", "Connecticut" => "CT", "Delaware" => "DE", "Dist of Columbia" => "DC", "Florida" => "FL", "Georgia" => "GA", "Hawaii" => "HI", "Idaho" => "ID", "Illinois" => "IL", "Indiana" => "IN", "Iowa" => "IA", "Kansas" => "KS", "Kentucky" => "KY", "Louisiana" => "LA", "Maine" => "ME", "Maryland" => "MD", "Massachusetts" => "MA", "Michigan" => "MI", "Minnesota" => "MN", "Mississippi" => "MS", "Missouri" => "MO", "Montana" => "MT", "Nebraska" => "NE", "Nevada" => "NV", "New Hampshire" => "NH", "New Jersey" => "NJ", "New Mexico" => "NM", "New York" => "NY", "North Carolina" => "NC", "North Dakota" => "ND", "Ohio" => "OH", "Oklahoma" => "OK", "Oregon" => "OR", "Pennsylvania" => "PA", "Rhode Island" => "RI", "South Carolina" => "SC", "South Dakota" => "SD", "Tennessee" => "TN", "Texas" => "TX", "Utah" => "UT", "Vermont" => "VT", "Virginia" => "VA", "Washington" => "WA", "West Virginia" => "WV", "Wisconsin" => "WI", "Wyoming" => "WY"); if (!isset($_GET )) { $page = 1; } else { $page = $_GET ; } //end if $max_results = 10; $from = (($page * $max_results) - $max_results); if (isset($_POST[submit])) { session_destroy(); //start the query statement for the search fields-starting with key word for default $query = "SELECT * FROM pub_gardens WHERE"; $end_query = ""; //if the user selects a type of facility from drop down menu, add on to the query string //also make sure the first value of the drop down for the facility selection isnt the first $key_word = $_POST[key_word]; $type = $_POST[type]; $state = $_POST[state]; $city = $_POST[city]; $zip = $_POST[zip]; if ($key_word != "") { $query .= " facility LIKE '%$key_word%'"; $end_query .= " facility LIKE '%$key_word%'"; } //end if if (($city == "City" || $city == "")) { $city = ""; } //end if if (($zip == "Zip Code" || $zip == "")) { $zip = ""; } //end if if ($type != "None") { if ($key_word == "") { $query .= " type = '$type'"; $end_query .= " type = '$type'"; } else { $query .= " OR type = '$type'"; $end_query .= " OR type = '$type'"; } //end if } //end if //if the user selects a state from drop down menu, add on to the query string //also make sure the first value of the drop down for the state selection isnt the first if ($state != "State") { if (($key_word == "" && $type == "None")) { $query .= " state = '$state'"; $end_query .= " state = '$state'"; } else { $query .= " OR state = '$state'"; $end_query .= " OR state = '$state'"; } //end if } //end if //if the user types in a city in the city field from the form, add on to the query string if ($city != "") { if (($key_word == "" && $type == "None" && $state == "State")) { $query .= " city LIKE '%$city'"; $end_query .= " city LIKE '%$city'"; } else { $query .= " OR city LIKE '%$city'"; $end_query .= " OR city LIKE '%$city'"; } //end if } //end if //if the user types in a zip code in the zip field from the form, add on to the query string if ($zip != "") { if (($key_word == "" && $type == "None" && $state == "State" && $city == "")) { $query .= " zip LIKE '%$zip'"; $end_query .= " zip LIKE '%$zip'"; } else { $query .= " OR zip LIKE '%$zip'"; $end_query .= " OR zip LIKE '%$zip'"; } //end if } //end if //add on last addition to the $query string variable $query .= " ORDER BY facility LIMIT $from, $max_results"; $result = mysql_query($query) or die(mysql_error() . " : " .__LINE__); //set session variables session_start(); $_SESSION['form_type'] = $type; $_SESSION['form_state'] = $state; $_SESSION['form_city'] = $city; $_SESSION['form_zip'] = $zip; $_SESSION['form_key_word'] = $key_word; //query session $_SESSION['end_query'] = $end_query; $_SESSION['query'] = $query; print_r($_SESSION); //start table $display = "<font color = \"#ff0000\">*Types (A = Arboretum, G = Garden, C = Conservatory, P = Park)</font>\n"; $display .= "<table border = 0 width = 500 cellspacing = 0>\n"; $display .= "<tr>\n"; $display .= "<th>Facility</th>\n"; $display .= "<th>State</th>\n"; $display .= "<th>Type</th>\n"; $display .= "</tr>\n\n"; //background color for <tr> $bgcolor = "#f5fffa"; while ($row = mysql_fetch_array($result)) { if ($bgcolor == "#f5fffa") { $bgcolor = "#ffffff"; } else { $bgcolor = "#f5fffa"; } //end if //display table row data $display .= "<tr bgcolor = \"".$bgcolor."\">\n"; $display .= "<td><a href = 'view_facility.php?f=$row[iD]'>$row[facility]</a></td>\n"; $display .= "<td>$row[state]</td>\n"; $display .= "<td>$row[type]</td>\n"; $display .= "</tr>\n"; } //end while $display .= "</table>\n"; // Figure out the total number of results in DB: $t_query = "SELECT COUNT(*) as Num FROM pub_gardens WHERE"; $_SESSION['t_query'] = $t_query . $end_query; //result $t_result = mysql_query($t_query . $end_query) or die(mysql_error() . " : " .__LINE__); $total_results = mysql_result($t_result,0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks // Build Previous Link if ($page > 1) { $prev = ($page - 1); $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$prev\"><< PREVIOUS</a> "; } //end if for ($i = 1; $i <= $total_pages; $i++) { if (($page) == $i) { $display .= "<strong>$i</strong> "; } else { $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$i\">$i</a> "; } //end if } //end if // Build Next Link if ($page < $total_pages) { $next = ($page + 1); $display .= " <a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$next\">NEXT >></a>"; } //end if /* //put "type" into options foreach ($fac_type as $type) { $type_option .= "<option value = \"$type\">$type</option>"; } //end foreach */ foreach ($fac_type as $type => $letters) { $type_option .= "<option value = $letters\n"; if ($type == $letters) { $type_option .= " SELECTED\n"; } //end if $type_option .= ">$type</option>\n"; } //end foreach /* //put "state" into options foreach ($fac_state as $state => $ac) { $state_option .= "<option value = \"$ac\">$state</option>"; } //end foreach */ foreach ($fac_state as $state => $ac) { $state_option .= "<option value = $ac\n"; if ($state == $ac) { $state_option .= " SELECTED\n"; } //end if $state_option .= ">$state</option>\n"; } //end if } else { //add on last addition to the $query string variable $query = $_SESSION['query']; $result = mysql_query($query) or die(mysql_error() . " : " .__LINE__); //start table $display = "<font color = \"#ff0000\">*Types (A = Arboretum, G = Garden, C = Conservatory, P = Park)</font>\n"; $display .= "<table border = 0 width = 500 cellspacing = 0>\n"; $display .= "<tr>\n"; $display .= "<th>Facility</th>\n"; $display .= "<th>State</th>\n"; $display .= "<th>Type</th>\n"; $display .= "</tr>\n\n"; //background color for <tr> $bgcolor = "#f5fffa"; while ($row = mysql_fetch_array($result)) { if ($bgcolor == "#f5fffa") { $bgcolor = "#ffffff"; } else { $bgcolor = "#f5fffa"; } //end if //display table row data $display .= "<tr bgcolor = \"".$bgcolor."\">\n"; $display .= "<td><a href = 'view_facility.php?f=$row[iD]'>$row[facility]</a></td>\n"; $display .= "<td>$row[state]</td>\n"; $display .= "<td>$row[type]</td>\n"; $display .= "</tr>\n"; } //end while $display .= "</table>\n"; $t_query = $_SESSION['t_query']; $t_result = mysql_query($t_query) or die(mysql_error() . " : " .__LINE__); $total_results = mysql_result($t_result,0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks // Build Previous Link if ($page > 1) { $prev = ($page - 1); $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$prev\"><< PREVIOUS</a> "; } //end if for ($i = 1; $i <= $total_pages; $i++) { if (($page) == $i) { $display .= "<strong>$i</strong> "; } else { $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$i\">$i</a> "; } //end if } //end if // Build Next Link if ($page < $total_pages) { $next = ($page + 1); $display .= " <a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$next\">NEXT >></a>"; } //end if //put "type" into options foreach ($fac_type as $type) { $type_option .= "<option value = \"$type\">$type</option>"; } //end foreach foreach ($fac_type as $type => $letters) { $type_option .= "<option value = $letters\n"; if ($_SESSION['form_type'] == $letters) { $type_option .= " SELECTED\n"; } //end if $type_option .= ">$type</option>\n"; } //end foreach //put "state" into options foreach ($fac_state as $state => $ac) { $state_option .= "<option value = \"$ac\">$state</option>"; } //end foreach foreach ($fac_state as $state => $ac) { $state_option .= "<option value = $ac\n"; if ($_SESSION['form_state'] == $ac) { $state_option .= " SELECTED\n"; } //end if $state_option .= ">$state</option>\n"; } //end if } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>eCountryLifestyle: Public Garden Directory</title> <link href="../../_css/style_popup.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="layoutContainer"> <div id="headerHome"><img src="../images/public_garden_directory_banner.jpg" alt="Public Garden Directory" width="784" height="182" /></div> <div id="contentLayout"> <div id="searchLayoutChecklist"> <div class="topLinkTextNormalHeading" >Browse by Facility Name: <span class="topLinkTextNormal"><?php print "$links_top"; ?></span></div> </div> <div id="content"> <div id="contents"> <div id="sidebarLayout"> <p align="center"><a href="http://www.cotton.org/index.cfm" target="_blank"><img src="../images/associations/national_cotton_counsel.jpg" alt="National Cotton Counsil" width="180" height="90" border="0" /></a></p> <p> </p> <p align="center"><a href="http://www.mulchandsoilcouncil.org/index.html" target="_blank"><img src="../images/associations/mulch_and_soil_counsl.jpg" alt="Mulch and Soil Council" width="180" height="157" border="0" /></a></p> <p> </p> <p align="center"><a href="http://www.bluediamond.com/" target="_blank"><img src="../images/associations/blue_diamond_almonds.jpg" alt="Blue Diamonds Almonds" width="180" height="127" border="0" /></a></p> <p> </p> <p align="center"><a href="http://www.naturalproductsassoc.org/site/PageServer" target="_blank"><img src="../images/associations/natural_pro_assocn.jpg" alt="National Products Association" width="180" height="82" border="0" /></a></p> </div> <h1 class="subtitle">Public Garden Directory<br /> <br /> </h1> <?php print "$display"; ?><br><br> <table width="525" border="0" cellpadding="2" cellspacing="0" class="table_box"> <tr> <td class="table_row_header1"><strong>Search</strong></td> </tr> <tr> <td class="table_main_content"> <form class = "form1" action = "advanced_search.php" method = "post"> <table border = 0> <tr> <td colspan = 2><select name = "type"><?php echo "$type_option"; ?></select></td> </tr> <tr> <td height = 30 colspan = 2 valign = "bottom"><select name = "state"><?php echo "$state_option"; ?></select></td> </tr> <tr> <td height = 30 valign = "bottom"><input class = "form1" type = "text" name = "zip" size = 6 maxlength = 12 value = "<?=$_SESSION[form_zip];?>"></td> <td height = 30 valign = "bottom"><input class = "form1" type = "text" name = "city" size = 10 maxlength = 30 value = "<?=$_SESSION[form_city];?>"></td> </tr> <tr> <td colspan = 2 valign = "bottom">Key Word(s):</td> </tr> <tr> <td><input class = "form1" type = "text" name = "key_word" size = 20 maxlength = 100 value = "<?=$_SESSION[form_key_word];?>"></td> <td><input class = "button" type = "submit" name = "submit" value = "Search"></td> </tr> </table> </form> </td> </tr> </table> <p> </p> </div> </div> </div> </div> </body> </html> I've tried everything possible to get the pagination part working...please help Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/ Share on other sites More sharing options...
Neptunus Maris Posted September 12, 2007 Author Share Posted September 12, 2007 Would sessions work with this? thats what ive been trying Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/#findComment-347107 Share on other sites More sharing options...
colombian Posted September 12, 2007 Share Posted September 12, 2007 Hey, The first thing you need to do is secure your database information, unless you don't care much about that file. .inc extensions by themselves are completely insecure. To have a little better security make them .inc.php or just keep them as .php files. Basically, right now anybody can just go to: http://devel.ecountrylifestyle.com/includes/PHP/globals_db.inc Since the servers do not understand a .inc extension is just gives the code away. Just a word of caution. Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/#findComment-347118 Share on other sites More sharing options...
Neptunus Maris Posted September 12, 2007 Author Share Posted September 12, 2007 Hey, The first thing you need to do is secure your database information, unless you don't care much about that file. .inc extensions by themselves are completely insecure. To have a little better security make them .inc.php or just keep them as .php files. Basically, right now anybody can just go to: http://devel.ecountrylifestyle.com/includes/PHP/globals_db.inc Since the servers do not understand a .inc extension is just gives the code away. Just a word of caution. Ok thanks...but can you help me with this pagination crisis? Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/#findComment-347135 Share on other sites More sharing options...
colombian Posted September 12, 2007 Share Posted September 12, 2007 Well, the code is very long, not sure where the problem can be. The pagination I have worked with works something like this: <?php define('COLS', 1); define('SHOWMAX', 15); //max results per page $getTotal = 'SELECT COUNT(*) FROM dealers'; //total in the search (I am doing a query here though) $total = mysql_query($getTotal); //you need to track the total number of results in variable $row = mysql_fetch_row($total); //fetching date $totalDealers = $row[0]; $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; //tracking current page (if else stmt) $startRow = $curPage * SHOWMAX; //important - where it starts $query = "SELECT * FROM dealers ORDER BY county ASC LIMIT $startRow,".SHOWMAX; //!important $dealer_set = mysql_query($query, $connection); check_query($dealer_set); $dealer_count = mysql_num_rows($dealer_set); ?> <table width="90%" border="1"> <caption style="text-align:left; font-weight:bold; padding-bottom:.5em;">Displaying dealers <?php echo $startRow+1; if ($startRow+1 < $totalDealers) { echo ' to '; if ($startRow+SHOWMAX < $totalDealers) { echo $startRow+SHOWMAX; } else { echo $totalDealers; } } echo " of $totalDealers"; ?> <span style="float:right"> <?php if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'"> < Prev </a> '; } else { echo ' '; } if ($startRow+SHOWMAX < $totalDealers) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'"> | Next ></a> '; } else { echo ' '; //navigating through results } ?></span> </caption> while($row = mysql_fetch_array($dealer_set)) { $id = $row['id']; $name = $row['name']; $county = $row['county']; // echo stuff in html/php whatever } // END WHILE ?> ?> Hope that helps, I am happy with it, since it is fairly compact. Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/#findComment-347163 Share on other sites More sharing options...
Neptunus Maris Posted September 12, 2007 Author Share Posted September 12, 2007 That didnt work... but here is an update of the latest: <?php //connect //Programmed by: Rashaud Teague (Tank Diesel) include('../../includes/PHP/globals_db.inc'); $dbconn = mysql_connect($ecl_database_server, $ecl_username, $ecl_password) or die(mysql_error()); $select = mysql_select_db($ecl_database, $dbconn) or die(mysql_error()); //------------ //first lets make an array of letters A-Z $alpha = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "Y", "Z"); $links_top = ""; foreach ($alpha as $links) { $links_top .= "<a class = \"checklist\" href = 'facilities.php?fac=$links'>"; if ($links == "Z") { $links_top .= "$links</a>"; } else { $links_top .= "$links</a> | "; } //end if } //end if //type array $fac_type = array("Type of Facility" => "None", "Arboretum" => "A", "Arboretum/Garden" => "A, G", "Garden" => "G", "Garden/Arboretum" => "G, A", "Park" => "P", "Park/Garden" => "P, G", "Garden/Park" => "G, P", "Conservatory" => "C"); //states $fac_state = array("State Select" => "State", "Alabama" => "AL", "Alaska" => "AL", "Arizona" => "AZ", "Arkansas" => "AK", "California" => "CA", "Colorado" => "CO", "Connecticut" => "CT", "Delaware" => "DE", "Dist of Columbia" => "DC", "Florida" => "FL", "Georgia" => "GA", "Hawaii" => "HI", "Idaho" => "ID", "Illinois" => "IL", "Indiana" => "IN", "Iowa" => "IA", "Kansas" => "KS", "Kentucky" => "KY", "Louisiana" => "LA", "Maine" => "ME", "Maryland" => "MD", "Massachusetts" => "MA", "Michigan" => "MI", "Minnesota" => "MN", "Mississippi" => "MS", "Missouri" => "MO", "Montana" => "MT", "Nebraska" => "NE", "Nevada" => "NV", "New Hampshire" => "NH", "New Jersey" => "NJ", "New Mexico" => "NM", "New York" => "NY", "North Carolina" => "NC", "North Dakota" => "ND", "Ohio" => "OH", "Oklahoma" => "OK", "Oregon" => "OR", "Pennsylvania" => "PA", "Rhode Island" => "RI", "South Carolina" => "SC", "South Dakota" => "SD", "Tennessee" => "TN", "Texas" => "TX", "Utah" => "UT", "Vermont" => "VT", "Virginia" => "VA", "Washington" => "WA", "West Virginia" => "WV", "Wisconsin" => "WI", "Wyoming" => "WY"); if (!isset($_GET )) { $page = 1; } else { $page = $_GET ; } //end if $max_results = 10; $from = (($page * $max_results) - $max_results); if (isset($_POST[submit])) { session_destroy(); //start the query statement for the search fields-starting with key word for default $query = "SELECT * FROM pub_gardens WHERE"; $end_query = ""; //if the user selects a type of facility from drop down menu, add on to the query string //also make sure the first value of the drop down for the facility selection isnt the first $key_word = $_POST[key_word]; $type = $_POST[type]; $state = $_POST[state]; $city = $_POST[city]; $zip = $_POST[zip]; if ($key_word != "") { $query .= " facility LIKE '%$key_word%'"; $end_query .= " facility LIKE '%$key_word%'"; } //end if if (($city == "City" || $city == "")) { $city = ""; } //end if if (($zip == "Zip Code" || $zip == "")) { $zip = ""; } //end if if ($type != "None") { if ($key_word == "") { $query .= " type = '$type'"; $end_query .= " type = '$type'"; } else { $query .= " OR type = '$type'"; $end_query .= " OR type = '$type'"; } //end if } //end if //if the user selects a state from drop down menu, add on to the query string //also make sure the first value of the drop down for the state selection isnt the first if ($state != "State") { if (($key_word == "" && $type == "None")) { $query .= " state = '$state'"; $end_query .= " state = '$state'"; } else { $query .= " OR state = '$state'"; $end_query .= " OR state = '$state'"; } //end if } //end if //if the user types in a city in the city field from the form, add on to the query string if ($city != "") { if (($key_word == "" && $type == "None" && $state == "State")) { $query .= " city LIKE '%$city'"; $end_query .= " city LIKE '%$city'"; } else { $query .= " OR city LIKE '%$city'"; $end_query .= " OR city LIKE '%$city'"; } //end if } //end if //if the user types in a zip code in the zip field from the form, add on to the query string if ($zip != "") { if (($key_word == "" && $type == "None" && $state == "State" && $city == "")) { $query .= " zip LIKE '%$zip'"; $end_query .= " zip LIKE '%$zip'"; } else { $query .= " OR zip LIKE '%$zip'"; $end_query .= " OR zip LIKE '%$zip'"; } //end if } //end if //add on last addition to the $query string variable $query .= " ORDER BY facility LIMIT $from, $max_results"; $result = mysql_query($query) or die(mysql_error() . " : " .__LINE__); //set session variables session_start(); $_SESSION['form_type'] = $type; $_SESSION['form_state'] = $state; $_SESSION['form_city'] = $city; $_SESSION['form_zip'] = $zip; $_SESSION['form_key_word'] = $key_word; //query session $_SESSION['end_query'] = $end_query; $_SESSION['query'] = $query; print_r($_SESSION); //start table $display = "<font color = \"#ff0000\">*Types (A = Arboretum, G = Garden, C = Conservatory, P = Park)</font>\n"; $display .= "<table border = 0 width = 500 cellspacing = 0>\n"; $display .= "<tr>\n"; $display .= "<th>Facility</th>\n"; $display .= "<th>State</th>\n"; $display .= "<th>Type</th>\n"; $display .= "</tr>\n\n"; //background color for <tr> $bgcolor = "#f5fffa"; while ($row = mysql_fetch_array($result)) { if ($bgcolor == "#f5fffa") { $bgcolor = "#ffffff"; } else { $bgcolor = "#f5fffa"; } //end if //display table row data $display .= "<tr bgcolor = \"".$bgcolor."\">\n"; $display .= "<td><a href = 'view_facility.php?f=$row[iD]'>$row[facility]</a></td>\n"; $display .= "<td>$row[state]</td>\n"; $display .= "<td>$row[type]</td>\n"; $display .= "</tr>\n"; } //end while $display .= "</table>\n"; // Figure out the total number of results in DB: $t_query = "SELECT COUNT(*) as Num FROM pub_gardens WHERE"; $_SESSION['t_query'] = $t_query . $end_query; //result $t_result = mysql_query($t_query . $end_query) or die(mysql_error() . " : " .__LINE__); $total_results = mysql_result($t_result,0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks // Build Previous Link if ($page > 1) { $prev = ($page - 1); $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$prev\"><< PREVIOUS</a> "; } //end if for ($i = 1; $i <= $total_pages; $i++) { if (($page) == $i) { $display .= "<strong>$i</strong> "; } else { $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$i\">$i</a> "; } //end if } //end if // Build Next Link if ($page < $total_pages) { $next = ($page + 1); $display .= " <a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$next\">NEXT >></a>"; } //end if /* //put "type" into options foreach ($fac_type as $type) { $type_option .= "<option value = \"$type\">$type</option>"; } //end foreach */ foreach ($fac_type as $type => $letters) { $type_option .= "<option value = $letters\n"; if ($type == $letters) { $type_option .= " SELECTED\n"; } //end if $type_option .= ">$type</option>\n"; } //end foreach /* //put "state" into options foreach ($fac_state as $state => $ac) { $state_option .= "<option value = \"$ac\">$state</option>"; } //end foreach */ foreach ($fac_state as $state => $ac) { $state_option .= "<option value = $ac\n"; if ($state == $ac) { $state_option .= " SELECTED\n"; } //end if $state_option .= ">$state</option>\n"; } //end if } else { //add on last addition to the $query string variable session_start(); $query = $_SESSION['query']; $result = mysql_query($query) or die(mysql_error() . " : " .__LINE__); print_r($_SESSION); //start table $display = "<font color = \"#ff0000\">*Types (A = Arboretum, G = Garden, C = Conservatory, P = Park)</font>\n"; $display .= "<table border = 0 width = 500 cellspacing = 0>\n"; $display .= "<tr>\n"; $display .= "<th>Facility</th>\n"; $display .= "<th>State</th>\n"; $display .= "<th>Type</th>\n"; $display .= "</tr>\n\n"; //background color for <tr> $bgcolor = "#f5fffa"; while ($row = mysql_fetch_array($result)) { if ($bgcolor == "#f5fffa") { $bgcolor = "#ffffff"; } else { $bgcolor = "#f5fffa"; } //end if //display table row data $display .= "<tr bgcolor = \"".$bgcolor."\">\n"; $display .= "<td><a href = 'view_facility.php?f=$row[iD]'>$row[facility]</a></td>\n"; $display .= "<td>$row[state]</td>\n"; $display .= "<td>$row[type]</td>\n"; $display .= "</tr>\n"; } //end while $display .= "</table>\n"; $t_query = $_SESSION['t_query']; $t_result = mysql_query($t_query) or die(mysql_error() . " : " .__LINE__); $total_results = mysql_result($t_result,0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks // Build Previous Link if ($page > 1) { $prev = ($page - 1); $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$prev\"><< PREVIOUS</a> "; } //end if for ($i = 1; $i <= $total_pages; $i++) { if (($page) == $i) { $display .= "<strong>$i</strong> "; } else { $display .= "<a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$i\">$i</a> "; } //end if } //end if // Build Next Link if ($page < $total_pages) { $next = ($page + 1); $display .= " <a class = \"checklist\" href=\"".$_SERVER[php_SELF]."?page=$next\">NEXT >></a>"; } //end if //put "type" into options foreach ($fac_type as $type) { $type_option .= "<option value = \"$type\">$type</option>"; } //end foreach foreach ($fac_type as $type => $letters) { $type_option .= "<option value = $letters\n"; if ($_SESSION['form_type'] == $letters) { $type_option .= " SELECTED\n"; } //end if $type_option .= ">$type</option>\n"; } //end foreach //put "state" into options foreach ($fac_state as $state => $ac) { $state_option .= "<option value = \"$ac\">$state</option>"; } //end foreach foreach ($fac_state as $state => $ac) { $state_option .= "<option value = $ac\n"; if ($_SESSION['form_state'] == $ac) { $state_option .= " SELECTED\n"; } //end if $state_option .= ">$state</option>\n"; } //end if } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>eCountryLifestyle: Public Garden Directory</title> <link href="../../_css/style_popup.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="layoutContainer"> <div id="headerHome"><img src="../images/public_garden_directory_banner.jpg" alt="Public Garden Directory" width="784" height="182" /></div> <div id="contentLayout"> <div id="searchLayoutChecklist"> <div class="topLinkTextNormalHeading" >Browse by Facility Name: <span class="topLinkTextNormal"><?php print "$links_top"; ?></span></div> </div> <div id="content"> <div id="contents"> <div id="sidebarLayout"> <p align="center"><a href="http://www.cotton.org/index.cfm" target="_blank"><img src="../images/associations/national_cotton_counsel.jpg" alt="National Cotton Counsil" width="180" height="90" border="0" /></a></p> <p> </p> <p align="center"><a href="http://www.mulchandsoilcouncil.org/index.html" target="_blank"><img src="../images/associations/mulch_and_soil_counsl.jpg" alt="Mulch and Soil Council" width="180" height="157" border="0" /></a></p> <p> </p> <p align="center"><a href="http://www.bluediamond.com/" target="_blank"><img src="../images/associations/blue_diamond_almonds.jpg" alt="Blue Diamonds Almonds" width="180" height="127" border="0" /></a></p> <p> </p> <p align="center"><a href="http://www.naturalproductsassoc.org/site/PageServer" target="_blank"><img src="../images/associations/natural_pro_assocn.jpg" alt="National Products Association" width="180" height="82" border="0" /></a></p> </div> <h1 class="subtitle">Public Garden Directory<br /> <br /> </h1> <?php print "$display"; ?><br><br> <table width="525" border="0" cellpadding="2" cellspacing="0" class="table_box"> <tr> <td class="table_row_header1"><strong>Search</strong></td> </tr> <tr> <td class="table_main_content"> <form class = "form1" action = "advanced_search.php" method = "post"> <table border = 0> <tr> <td colspan = 2><select name = "type"><?php echo "$type_option"; ?></select></td> </tr> <tr> <td height = 30 colspan = 2 valign = "bottom"><select name = "state"><?php echo "$state_option"; ?></select></td> </tr> <tr> <td height = 30 valign = "bottom"><input class = "form1" type = "text" name = "zip" size = 6 maxlength = 12 value = "<?=$_SESSION[form_zip];?>"></td> <td height = 30 valign = "bottom"><input class = "form1" type = "text" name = "city" size = 10 maxlength = 30 value = "<?=$_SESSION[form_city];?>"></td> </tr> <tr> <td colspan = 2 valign = "bottom">Key Word(s):</td> </tr> <tr> <td><input class = "form1" type = "text" name = "key_word" size = 20 maxlength = 100 value = "<?=$_SESSION[form_key_word];?>"></td> <td><input class = "button" type = "submit" name = "submit" value = "Search"></td> </tr> </table> </form> </td> </tr> </table> <p> </p> </div> </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/#findComment-347240 Share on other sites More sharing options...
colombian Posted September 12, 2007 Share Posted September 12, 2007 What type of errors are you getting? SQL error? it hangs? Are you getting all the results in 1 page? Are the navigation links not working? If so, do some dubigging, like make it LIMIT 4. If it only shows 4 results, but with your variable it doesn't work, then the error is coming from there. This way we can isolate what part isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/69059-paginationwith-my-search-engine/#findComment-347343 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.