#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Search for a keyword in a database


    I simply want to create a search box, enter a keyword in it, search the database for this keyword and load the corresponding subpage. Here is an example of what I am trying to accomplish. Let's say I have travel website with two sub-pages for New York and San Francisco ( newyork.travel.com and sanfrancisco.travel.com ). My database has two raws with the names of my sub-pages. Now when I enter Ney York in the search box I want to search the database and if there is a match then newyork.travel.com should be opened in the browser.

    Can you please advise me how to do it? I know how to create a search box and a database, I also know how to create a sql query. What I don't know is how to load a page when a match is found in my database. What function or method should I use.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,866
    Rep Power
    6351
    header() can redirect users to new pages:

    PHP Code:
    header('Location: http://newyork.yoursite.com');
    die(); 
    Have you thought about what happens if you have more than one entry returned? Do you have a new york city and a new york state visitor's guide?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Thank you. I will definitely try that function. New York city was just an example. Each field in my database will have a unique name. But just out of curiosity if I have two entries returned what would be the best way to handle them?

IMN logo majestic logo threadwatch logo seochat tools logo