good morning everyone. i have pretty much correctly implemented a browsing function to look at table information 3 rows at a time. here's the problem: my front end builds the search query from user-entered information, so when i hit the "Next" button to see the next 3 rows that fit the query, that user information is no longer there, and the query is built with no information to go on. so when i hit "Next" it just says "No rows found matching your criteria." I know that I somehow have to save the original query or query information so the function can use it over and over. I am not sure how to do this...it seems complicated to me. here is my code....any help is greatly appreciated. THANKS!!!!!!!!!!!!!!!

also let me know if you wanna see th4e browse3() function code.

<?php

include	"iprange.inc";
include	"error.inc";
include	"paths.inc";
include	"functions2.php";

if ( !empty($_POST["descr"]) || !empty($_POST["network"]) || !empty($_POST["size_dropdown"]) || !empty($_GET["offset"]) )
{
	// initialize browse3() params
	$scriptName = "search_unavailable.php";

	// set $offset to zero if not previously set
	if ( empty($offset) )
		$offset = 0;

	$offset = $_GET['offset'];

	// HTML <TABLE> column headers
	$header[0]["header"] = "Id";
	$header[1]["header"] = "Network";
	$header[2]["header"] = "Mask";
	$header[3]["header"] = "Size";
	$header[4]["header"] = "Type";
	$header[5]["header"] = "Router Info";
	$header[6]["header"] = "Description";
	$header[7]["header"] = "Member Id";
	$header[8]["header"] = "User";
	$header[9]["header"] = "Assigned";

	// query attributes to display in <TABLE> columns
	$header[0]["attrib"] = "id";
	$header[1]["attrib"] = "network";
	$header[2]["attrib"] = "mask";
	$header[3]["attrib"] = "size";
	$header[4]["attrib"] = "type";
	$header[5]["attrib"] = "router_info";
	$header[6]["attrib"] = "description";
	$header[7]["attrib"] = "member_id";
	$header[8]["attrib"] = "user";
	$header[9]["attrib"] = "assigned";

	// (1) Open the database connection
	$connection = mysql_connect($hostName,$username,$password);

	// (2) Select the database
	mysql_select_db($databaseName, $connection); // 
	

	// start beginning of query to build on
	$query = "SELECT * FROM subnets WHERE ";

	// build a query for just a description search
	if ( !empty($_POST["descr"]) && empty($_POST["network"]) )
	{
		$query .= "description = '" . $_POST['descr'] . "'";
	}

	// build a query for just a network search
	if ( !empty($_POST["network"]) )
	{
		// build a query for a search on description AND network
		if ( !empty($_POST["description"]) )
		{
			$query .= "description = '" . $_POST['descr'] .
				"' AND network = '" . $_POST['network'] . "'";
		}
		else
		{
			$query .= "network = '" . $_POST['network'] . "'";
		}
		
	}

	// build a query for just a size search
	if ( empty($_POST["descr"]) && empty($_POST["network"]) )
		$query .= "size = '" . $_POST['size_dropdown'] . "'";

	$query .= " AND (assigned = 1 OR assigned = 2) ORDER BY network";

	// use the browse3() function
	browse3( $scriptName, $connection, $offset, $query, $header );

/*
	// run the query on the connection
	if (!($result = @ mysql_query ($query, $connection)))
		showerror();

	// display the results
	displayIPtable($result);

*/

	// choose to browse more or go to main menu
	echo	'<form name="browse_options" method="post" action="search_unavailable.php"><p>' .
		'<input type="button" value="Browse More Networks" 
			onclick="window.location.href=\'search_unavailable.php\'"><p>' .
		'<input type="button" value="Main Menu" 
			onclick="window.location.href=\'interface.php\'" ><br><p>';
	echo	'</form><p>';


	// close the connection
	if (!(mysql_close($connection)))
		showerror();
}
else
{
	echo	'Search networks by description, network, or size. <br><p>';

	//~~~~~~~~~~~~~~~  CREATE FORM TO SUBMIT DESIRED NETWORK DESCRIPTION OR NETWORK  ~~~~~~~~~~~~~~~~~~~~~~~
	echo	'<form name="search_unavailable" method="post" action="search_unavailable.php">
			Description: ' .
		'<input type="text" name="descr" value="" size="55"><br>' .
		'Network: <input type="text" name="network" value="" size="35"><br><p>' .
		'Size: <select name="size_dropdown"><br>' .
					'<option value="">Choose one</option>' .
					'<option value="2">2</option>' .
					'<option value="6">6</option>' .
					'<option value="14">14</option>' .
					'<option value="30">30</option>' .
					'<option value="62">62</option>' .
					'<option value="126">126</option>' .
					'<option value="254">254</option>' .
					'<option value="1022">1022</option>' .
					'<option value="65534">65534</option>' .
				'</select><p>' .

		'<input type="submit" name="submit_all" value="Submit"><p>';
	echo	'</form><p>';
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}

?>

You will need to forward those values along in your GET requests (the Next/Previous links) or you can store them in $_SESSION[] to have them persist. Session is probably the easiest bet.

You will need to forward those values along in your GET requests (the Next/Previous links) or you can store them in $_SESSION[] to have them persist. Session is probably the easiest bet.

ok. can i store the entire query in $_SESSION[]? how can i store those values in $_SESSION[]? im a big time newbie so i relaly appreciate the help.

Small sample on storing a value in session:

<?php
  session_start();
  echo 'Sessions activated.<br />';
  $_SESSION['version'] = phpversion();
  echo 'Session data written.<br />';
  echo "Session data read: {$_SESSION['version']}.";
?>

Tutorial on sessions can be found here:
http://www.goodphptutorials.com/track/66

I don't think you will want to store the query itself in the session. That could be a lot of data for the server to serialize and deserialize. Just store enough info to requery as needed. You may want to up your result per page to 10 if the query is somewhat expensive to perform.

This article has been dead for over six months. Start a new discussion instead.