Search Item

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Search Item

Post by S_henry »

In my system, I have 1 search function to search student record. To search the student record, I just have to enter the student ID and then click the search button. Then the result will be displayed in 1 list. When I want to search for the second time, I want to display the result without remove the first result in that list. That's mean The result for the second search will be displayed with the result of the first one and so on. I think 1 of the solution is by using cookie. Can anybody explain how to do that pls? Thanx..
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Or just keep passing the previous search to the next page and then do a:

Code: Select all

SELECT * FROM students WHERE id = '$_POSTїsearch]' OR id = '$_POSTїsearch2]' OR id = '$_POSTїsearch3]';
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

In that SELECT statement, actually 'search' (from $_POST[search]) is variable name that we pass to search the item is it? In that statement also, just got 'search'...'search3' only. How about if we want to search the item until 10 times or more? Sorry if I misunderstood. Can anybody explain it pls? Thanx..
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Well that was just an example. In pratice you will have to produce a loop that will continue to add the search terms to the query. Might make it easier if you pass the number of search terms in the form as well, then you can just do:

Code: Select all

$sql = "SELECT * FROM students WHERE id = '$_POST[search]'";
for($x=1;$x<$_POST['number'];$x++){
   $sql .= " OR id = '$_POST[search-".$x."]'";
}
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

I see. Now I understand. Thanx kettle_drum. :D
Post Reply