Jump to content

Advanced Search


Neptunus Maris

Recommended Posts


I'm trying to do an advanced search with more than 2 fields to search from and I've never done this before.

 

my code:

 

<?php
<?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

if (isset($_POST[submit])) {
if (!isset($_GET

)) {
	$page = 1;
} else {
	$page = $_GET

;
} //end if

$max_results = 10;

$from = (($page * $max_results) - $max_results);

//start the query statement for the search fields-starting with key word for default
$query = "SELECT * FROM pub_gardens WHERE facility LIKE '$_POST[key_word]%'";

//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
if ($_POST[type] != "Type of Facility") {
	$query .= " AND type = '$_POST[type]'";
} //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 ($_POST[state] != "State") {
	$query .= " AND state = '$_POST[state]'";	
} //end if

//if the user types in a city in the city field from the form, add on to the query string
if ($_POST[city] != "") {
	//make sure the default value isnt "City" before adding on to the string
	if ($_POST[city] != "City") {
		$query .= " AND city LIKE '$_POST[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 ($_POST[zip] != "") {
	//make sure the default value isnt "Zip" before adding on to the string
	if ($_POST[zip] != "Zip") {
		$query .= " AND zip LIKE '$_POST[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__);

//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 facility LIKE '$_POST[key_word]%'";

//this section is the same type of code above
if ($_POST[type] != "Type of Facility") {
	$t_query .= " AND type = '$_POST[type]'";
} //end if

if ($_POST[state] != "State") {
	$t_query .= " AND state = '$_POST[state]'";	
} //end if

if ($_POST[city] != "") {
	if ($_POST[city] != "City") {
		$t_query .= " AND city LIKE '$_POST[city]%'";
	} //end if		
} //end if

if ($_POST[zip] != "") {
	if ($_POST[zip] != "Zip") {
		$t_query .= " AND zip LIKE '$_POST[zip]%'";
	} //end if
} //end if

//result
$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

//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");

/*
//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 ($_POST[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 ($_POST[state] == $ac) {
		$state_option .= "	SELECTED\n";
	} //end if

	$state_option .= ">$state</option>\n";
} //end if

//search
$search = "<form action = \"$_SERVER[php_SELF]\" method = \"post\">\n";
$search .= "<table border = 0>\n";
$search .= "<tr>\n";
$search .= "<td><select name = \"type\">$type_option</select></td>\n";
$search .= "<td></td>\n";
$search .= "<td></td>\n";
$search .= "</tr>\n\n";
$search .= "<tr>\n";
$search .= "<td><select name = \"state\">$state_option</select></td>\n";
$search .= "<td><input type = \"text\" name = \"city\" size = 10 maxlength = 30 value = \"$_POST[city]\"></td>\n";
$search .= "<td><input type = \"text\" name = \"zip\" size = 6 maxlength = 12 value = \"$_POST[zip]\"></td>\n";
$search .= "</tr>\n\n";
$search .= "<tr>\n";
$search .= "<td><strong>Key Word(s):</strong><input type = \"text\" name = \"key_word\" size = 20 maxlength = 100 value = \"$_POST[key_word]\"></td>\n";
$search .= "<td><input type = \"submit\" name = \"submit\" value = \"Search\"></td>\n";
$search .= "<td></td>\n";
$search .= "</tr>\n\n";
$search .= "</table>\n";
$search .= "</form>\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"><?php print "$search"; ?></td>
          </tr>
        </table>
        <p> </p>
      </div>
    </div>
  </div>
</div>
</body>
</html>
?>

 

 

The search isnt working...

 

Here is the link to a page that submits to the code above: http://devel.ecountrylifestyle.com/green_thumb_gardener/resources/facilities.php?fac=A

 

mind the bad table format with the search section.

Link to comment
Share on other sites

We sure have, but we do not wanna guess what your script does :)

 

You do not explain what kind of search you wanna do... all you do is throw your whole script where most likely 90% of the code has nothing to do with the actual search.

 

Are you trying to search a database with multiple LIKE statements or are you doing some regex stuff?

 

Please explain some more and what part isn't working.

 

Wuhtzu

 

 

Link to comment
Share on other sites

We sure have, but we do not wanna guess what your script does :)

 

You do not explain what kind of search you wanna do... all you do is throw your whole script where most likely 90% of the code has nothing to do with the actual search.

 

Are you trying to search a database with multiple LIKE statements or are you doing some regex stuff?

 

Please explain some more and what part isn't working.

 

Wuhtzu

 

 

 

I'm trying to use multiple LIKE statments.

 

Whats not working? When I test it to search, no results display. I know it has to be with the $query selection variables.

Link to comment
Share on other sites


I've tried this...this does do the search and now displays content, but when I click the next button the next page of results do not show.

 

Does anybody else know how to do advanced searches with PHP?

 

here is the code that I just recently updated:

 

<?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

if (isset($_POST[submit])) {
if (!isset($_GET

)) {
	$page = 1;
} else {
	$page = $_GET

;
} //end if

$max_results = 10;

$from = (($page * $max_results) - $max_results);

//start the query statement for the search fields-starting with key word for default
$query = "SELECT * FROM pub_gardens WHERE facility LIKE '%$_POST[key_word]%'";

//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
if ($_POST[type] != "Type of Facility") {
	$query .= " OR type = '$_POST[type]'";
} //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 ($_POST[state] != "State") {
	$query .= " OR state = '$_POST[state]'";	
} //end if

//if the user types in a city in the city field from the form, add on to the query string
if ($_POST[city] != "") {
	//make sure the default value isnt "City" before adding on to the string
	if ($_POST[city] != "City") {
		$query .= " OR city LIKE '%$_POST[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 ($_POST[zip] != "") {
	//make sure the default value isnt "Zip" before adding on to the string
	if ($_POST[zip] != "Zip") {
		$query .= " OR zip LIKE '%$_POST[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__);

//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 facility LIKE '%$_POST[key_word]%'";

//this section is the same type of code above
if ($_POST[type] != "Type of Facility") {
	$t_query .= " OR type = '$_POST[type]'";
} //end if

if ($_POST[state] != "State") {
	$t_query .= " OR state = '$_POST[state]'";	
} //end if

if ($_POST[city] != "") {
	if ($_POST[city] != "City") {
		$t_query .= " OR city LIKE '%$_POST[city]'";
	} //end if		
} //end if

if ($_POST[zip] != "") {
	if ($_POST[zip] != "Zip") {
		$t_query .= " OR zip LIKE '%$_POST[zip]'";
	} //end if
} //end if

//result
$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

//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");

/*
//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 ($_POST[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 ($_POST[state] == $ac) {
		$state_option .= "	SELECTED\n";
	} //end if

	$state_option .= ">$state</option>\n";
} //end if
} //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 = "<?=$_POST[zip];?>"></td>
		<td height = 30 valign = "bottom"><input class = "form1" type = "text" name = "city" size = 10 maxlength = 30 value = "<?=$_POST[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 = "<?=$_POST[key_word];?>"></td>
		<td><input type = "submit" name = "submit" value = "Search" width = 120></td>
		</tr>
		</table>
		</form>
		</td>
          </tr>
        </table>
        <p> </p>
      </div>
    </div>
  </div>
</div>
</body>
</html>

Link to comment
Share on other sites

I was just about to reply that your search function seemed to work but I got distracted by some other activity...

 

There is no neatly defined thing called "advanced search with PHP". Right now your problem is pagination... You somehow have to use the query build by the user on the next page too...

Link to comment
Share on other sites

I was just about to reply that your search function seemed to work but I got distracted by some other activity...

 

There is no neatly defined thing called "advanced search with PHP". Right now your problem is pagination... You somehow have to use the query build by the user on the next page too...

 

Do you think you could help me with that?...I would love it of you would...because I have no idea what I'm doing here.

 

Link to comment
Share on other sites

First of all you have a problem because the code where you read from your database and display the results is only run if the user has pressed the submit button which is only the case on the first page - when he/she click a link for a new page the if($_POST[submit]) is not true... So first of all deal with this :)

 

Then regarding your pagination. It should not be too hard... you have already done some pagination on the site - <previous 1 2 3 4 next>. This involves a mysql query which reads database entries with an ID between x and y. On the first page from ID1 to ID10 and on the second page from ID11 to ID20 and so on. On each page you use the same query but different LIMIT statement.

 

If you have used a premade pagination script or are unsure how it actually works read these to tutorials:

 

http://www.phpfreaks.com/tutorials/73/0.php

http://www.phpfreaks.com/tutorials/43/0.php

 

Now what you need to do is store your query, which is build by the user by choosing and writing different search terms, for use on the next pages. This is to prevent the query displaying all entries in the dababase when the user click next (since the form isn't submitted and no search terms inserted into the query). So when you have finished  building your query and have it stored in the variable $query you simply store it in a session variable too: $_SESSION['query'] = $query. Now you can run mysql_query($_SESSION['query']) on the next pages.

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.