makeITfunctional Posted May 15, 2009 Share Posted May 15, 2009 Hi, PHPFreaks! I have a question for you. I have a PHP & MySQL site that I am trying to build and I am looking for a piece of PHP code that can help facilitate a search. Let me explain: I have a search page for a wedding registry. If you enter in the correct first name and the correct last name (matched against what is in the MySQL database) then it will take you to the exact webpage. If the search is NOT exact or has multiple results, then it will take you to a page that displays the results and you select which name you meant. To clarify: 1. You go to the search page and type in: Neil Armstrong 2. If there is only one Neil Armstrong in the database, you will be redirected to neilarmstrong1.php or neilarmstrong1.html 3. However, if there are 3 results for Neil Armstrong, you will be presented with the results page (let's call it a landing page) and from there you will choose which one you want: neilarmstrong1, 2, or 3. So, my question is, if there is an exact match from the search, how do you skip the "landing page" and go right to the php or HTML file? Sorry it is complicated, please let me know if I can help clarify. Thanks for your help and time! My regards. Quote Link to comment Share on other sites More sharing options...
JD* Posted May 15, 2009 Share Posted May 15, 2009 You can use the mysql "LIKE" search... $result = mysql_query("SELECT * FROM table WHERE name LIKE '%name_variable_here%'") What this does is finds a similarity in strings. You can do it based on first name, last name, full name...whatever you want/need. Then, just do a: if(mysql_num_rows($result) > 1) { //create splash page here with all results, linked by ID } else { //code here will get the result from the database, or redirect to the page that does it. } Quote Link to comment Share on other sites More sharing options...
makeITfunctional Posted May 16, 2009 Author Share Posted May 16, 2009 JD-- Thanks!!! You are a genius! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.