Jump to content

[SOLVED] PHP Exact Page Redirect


Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/158208-solved-php-exact-page-redirect/
Share on other sites

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.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.