RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 690 | Replies: 4
Reply
Join Date: Jun 2007
Location: Albany, NY
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

storing a query for later use

  #1  
Jul 23rd, 2007
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.

  1. <?php
  2.  
  3. include "iprange.inc";
  4. include "error.inc";
  5. include "paths.inc";
  6. include "functions2.php";
  7.  
  8. if ( !empty($_POST["descr"]) || !empty($_POST["network"]) || !empty($_POST["size_dropdown"]) || !empty($_GET["offset"]) )
  9. {
  10. // initialize browse3() params
  11. $scriptName = "search_unavailable.php";
  12.  
  13. // set $offset to zero if not previously set
  14. if ( empty($offset) )
  15. $offset = 0;
  16.  
  17. $offset = $_GET['offset'];
  18.  
  19. // HTML <TABLE> column headers
  20. $header[0]["header"] = "Id";
  21. $header[1]["header"] = "Network";
  22. $header[2]["header"] = "Mask";
  23. $header[3]["header"] = "Size";
  24. $header[4]["header"] = "Type";
  25. $header[5]["header"] = "Router Info";
  26. $header[6]["header"] = "Description";
  27. $header[7]["header"] = "Member Id";
  28. $header[8]["header"] = "User";
  29. $header[9]["header"] = "Assigned";
  30.  
  31. // query attributes to display in <TABLE> columns
  32. $header[0]["attrib"] = "id";
  33. $header[1]["attrib"] = "network";
  34. $header[2]["attrib"] = "mask";
  35. $header[3]["attrib"] = "size";
  36. $header[4]["attrib"] = "type";
  37. $header[5]["attrib"] = "router_info";
  38. $header[6]["attrib"] = "description";
  39. $header[7]["attrib"] = "member_id";
  40. $header[8]["attrib"] = "user";
  41. $header[9]["attrib"] = "assigned";
  42.  
  43. // (1) Open the database connection
  44. $connection = mysql_connect($hostName,$username,$password);
  45.  
  46. // (2) Select the database
  47. mysql_select_db($databaseName, $connection); //
  48.  
  49.  
  50. // start beginning of query to build on
  51. $query = "SELECT * FROM subnets WHERE ";
  52.  
  53. // build a query for just a description search
  54. if ( !empty($_POST["descr"]) && empty($_POST["network"]) )
  55. {
  56. $query .= "description = '" . $_POST['descr'] . "'";
  57. }
  58.  
  59. // build a query for just a network search
  60. if ( !empty($_POST["network"]) )
  61. {
  62. // build a query for a search on description AND network
  63. if ( !empty($_POST["description"]) )
  64. {
  65. $query .= "description = '" . $_POST['descr'] .
  66. "' AND network = '" . $_POST['network'] . "'";
  67. }
  68. else
  69. {
  70. $query .= "network = '" . $_POST['network'] . "'";
  71. }
  72.  
  73. }
  74.  
  75. // build a query for just a size search
  76. if ( empty($_POST["descr"]) && empty($_POST["network"]) )
  77. $query .= "size = '" . $_POST['size_dropdown'] . "'";
  78.  
  79. $query .= " AND (assigned = 1 OR assigned = 2) ORDER BY network";
  80.  
  81. // use the browse3() function
  82. browse3( $scriptName, $connection, $offset, $query, $header );
  83.  
  84. /*
  85. // run the query on the connection
  86. if (!($result = @ mysql_query ($query, $connection)))
  87. showerror();
  88.  
  89. // display the results
  90. displayIPtable($result);
  91.  
  92. */
  93.  
  94. // choose to browse more or go to main menu
  95. echo '<form name="browse_options" method="post" action="search_unavailable.php"><p>' .
  96. '<input type="button" value="Browse More Networks"
  97. onclick="window.location.href=\'search_unavailable.php\'"><p>' .
  98. '<input type="button" value="Main Menu"
  99. onclick="window.location.href=\'interface.php\'" ><br><p>';
  100. echo '</form><p>';
  101.  
  102.  
  103. // close the connection
  104. if (!(mysql_close($connection)))
  105. showerror();
  106. }
  107. else
  108. {
  109. echo 'Search networks by description, network, or size. <br><p>';
  110.  
  111. //~~~~~~~~~~~~~~~ CREATE FORM TO SUBMIT DESIRED NETWORK DESCRIPTION OR NETWORK ~~~~~~~~~~~~~~~~~~~~~~~
  112. echo '<form name="search_unavailable" method="post" action="search_unavailable.php">
  113. Description: ' .
  114. '<input type="text" name="descr" value="" size="55"><br>' .
  115. 'Network: <input type="text" name="network" value="" size="35"><br><p>' .
  116. 'Size: <select name="size_dropdown"><br>' .
  117. '<option value="">Choose one</option>' .
  118. '<option value="2">2</option>' .
  119. '<option value="6">6</option>' .
  120. '<option value="14">14</option>' .
  121. '<option value="30">30</option>' .
  122. '<option value="62">62</option>' .
  123. '<option value="126">126</option>' .
  124. '<option value="254">254</option>' .
  125. '<option value="1022">1022</option>' .
  126. '<option value="65534">65534</option>' .
  127. '</select><p>' .
  128.  
  129. '<input type="submit" name="submit_all" value="Submit"><p>';
  130. echo '</form><p>';
  131. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132. }
  133.  
  134. ?>
  135.  
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: storing a query for later use

  #2  
Jul 23rd, 2007
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.
Reply With Quote  
Join Date: Jun 2007
Location: Albany, NY
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

Re: storing a query for later use

  #3  
Jul 23rd, 2007
Originally Posted by Ezzaral View Post
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.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: storing a query for later use

  #4  
Jul 23rd, 2007
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.
Reply With Quote  
Join Date: Jun 2007
Location: Albany, NY
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

Re: storing a query for later use

  #5  
Jul 23rd, 2007
ok thanks a lot i've got it now.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:25 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC