Welcome to WebmasterWorld Guest from 18.104.22.168
I am working on a system that logs IP addresses, I posted earlier about pagination, which I now have sorted however I am now attempting to implement a search feature that will display the results and also offer the pagination.
The paghination is working like this
I have introduced a new file called search.php that has the following URI, mysite.com/search.php?ip=192.168.0.1&limit=10&page=1
my problem is getting the IP address or value typed into the search text box (the search text box appears at the top of the search.php file), How do i get the value from the search text box into the URI, and also how do i make it so that once it is in a variable that variable will never change, even if the page is reloaded (session variables?) so I suppose its more of how do i get the search text into a session variable, and then get the session variable into the URI for the ip attribute?
any help here would be appreciated, if you need to see code snippets just ask, I didn't want to post the entire code as its long and also incase the solution didn't need it.
anyhow any help appreciated as i mentioned before.
I am using a form text box to type the ip in lets say the ip i am typing is 10.0.0.0
so i type 10.0.0.0 and press "Search" this search button submits to search.php, which I want to be able to list all the IPs 10.0.0.0 from a database.
the problem I have is that i list 20 records for 10.0.0.0 per page, when i click next to goto the next page it doesn't remember the $_POST['textbox'] item from the first page and returns no results because the search criteria originally from $_POST['textbox'] isnt set anymore.
I added an extra field to the URI called IP now i can access my results correctly but only by hand modfying the URI to be
i want to be able to do this automatically and not have to hand modify the URI so if i type 10.0.0.0 into the text box and press search it should make the initial URI include the value i typed in the text box.
Do you get me?
I dont have a clue how to do this properly so I am here seeking guidance.
any thoughts at all will be much appreciated
echo '<input type="hidden" name="ip" value="'.$_POST[ip].'">';
and then access the IP from the $_POST array on the next page, or add the IP address in the <form> code like this:
echo '<form action="search.php?ip='.$_POST[ip].'">';
and access the IP address from the $_GET array.
Yea it is not supposed to. $_POST, $_REQUEST, $_GET, all get values of a form from just submitted forms, and you shouldn't expect them to be there by themselves in the following paes.
I would recommend you to assign them to a SESSION. May be put the id in the following manner:
$_SESSION['id'] = $_POST['textbox']; then use $_SESSION['id'] in the following pages.
or carry the values in hidden textboxes
<input type="hidden" value=". $_POST['textbox'] ." name = "textbox">
I hope this helps.
because when i click next, $_POST['textbox'] will not have been submitted to the next page so isnt it like saying
$_SESSION['ip'] = "/*nothing*/";
this is because when i click next to view the next page of results it loads the same file e.g.
search.php displays the first page of results based on the search criteria entered into the search box, on this initial search.php page i can click next if there are more than a certain number of results, my problem is that the search criteria isnt remembered because it reloads the search page which will store the $_POST['textbox'] value and sionce it reloads and theres nothing to post the value is empty when the page reloads.
since the $_POST['textbox'] field will be empty when i click next to view the next page of the search results.
so I thought that maybe I need to somehow get the value from $_POST['textbox'] into a $_GET value so that when i choose "next" on the first page of results it passes the search criteria onto the next page and so on and on....
I am not sure, any ideas?
PS- I was always throwing the idea of a session variale to store search criteria from the text box, not sure though thats why I am here .
[edited by: bysonary at 9:20 am (utc) on May 31, 2007]
here goes ill try explain once more
HOW do i get the value from the textbox, into the url header? I could use:
echo '<a href="search.php?ip='.$_POST['textbox'].'>Next</a>";
you see what I mean now? when im on page 1, its fine yeah but on page 2 nothing was previously entered into the textbox so using $_POST['textbox'] would be wrong, or am i wrong?
any further advice here appreciated
ps - is it possible without session variables?