-1

I am developing a website in PHP for booking the trains. When a user logins to his account he will be able to search available trains and he will get a number of available trains in another webpage.

I need to save the result page he got for the search, so that whenever he logs back to his account he can see his search history. Can anyone tell me the code for this?

1

4 Answers 4

3

Create a "history" table in database with user_id, keyword and time. Each time when someone search save his search to this table. As Mr. Alien suggest you can use session but this is temporary saving.

2

You can save his search history in a session variable

$_SESSION['search_history'];

Or else you can also maintain a table for storing their search results like

search table

--------------------
userid   |   search
--------------------
12345       whatever
86459       blah blah

Now when the user visits back you can simply retrieve the data matched with the user ID like

$query = SELECT search FROM search_table WHERE userid=$_SESSION['userid'];
4
  • I don't think the user is asking about session. so that whenever he log back to his account he can see his search history. it will involve storage too.
    – itachi
    Oct 31, 2012 at 15:22
  • @itachi Oh yes ..I missed that
    – Mr. Alien
    Oct 31, 2012 at 15:23
  • 1
    now +1. lol you really want this answer to be accepted. edit after edit. ;)
    – itachi
    Oct 31, 2012 at 15:27
  • @itachi haha I said I simply missed that out.. :)\
    – Mr. Alien
    Oct 31, 2012 at 15:28
1

if you want the history to be saved for all times you can save it to a database. a session would dissapear after a while.

1

Make a table in the database, with fields 1. user_id 2. word_searched. 3. dateandtime

When the search button is pressed save these in the table and for future you can get all the records in this table against the loged in user. Also you can put it in the text box to show the results again.

Not the answer you're looking for? Browse other questions tagged or ask your own question.