| | |
storing a query for later use
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
also let me know if you wanna see th4e browse3() function code.
php Syntax (Toggle Plain Text)
<?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>'; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } ?>
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Web Programmer
Adirondack Area Network, LLC
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.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Web Programmer
Adirondack Area Network, LLC
Small sample on storing a value in session: 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.
PHP Syntax (Toggle Plain Text)
<?php session_start(); echo 'Sessions activated.<br />'; $_SESSION['version'] = phpversion(); echo 'Session data written.<br />'; echo "Session data read: {$_SESSION['version']}."; ?>
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.
![]() |
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Storing if a user has viewed a post (Database Design)
- Query Building (Database Design)
Other Threads in the PHP Forum
- Previous Thread: view word/excel
- Next Thread: is it possible to store a query?
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner beneath binary broadband broken button cakephp checkbox class cms code compression countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html httppost image include insert integration ip javascript joomla limit link links login mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion remote script search searchbox server session sessions sms smtp source space sql strip_tags survey syntax system table tutorial update upload url validator variable video virus votedown web website window.onbeforeunload=closeme; youtube






