Click Here[1] UnderConstruction please go to upper link and click on SIGNUP TO DRIVE (Blue cruve Button) there will be a tab open type london (Not From Drop Down) only just type london and hit enter page will redirect to

dev.appcotech.com/pwrdup/static/become-postie-vehicle.php

page (This mean post keyword matched 100% with database) than come back to previous page and again type london now this time from Dropdown menu
you will find London, United Kingdom,and hit enter. They are same city but my database have only keyword london.so page will redirect to

dev.appcotech.com/pwrdup/static/city-unavailables.php

This mean result not matched 100%

I want to match only city London, United Kingdom to my database Keyword london.
I only have letters london in my database here is my code.

require_once "connection/connection.php";
if($_POST)
{ 
   $a  = $_POST['address'] ;
   $sql = "SELECT * FROM tbl_city WHERE city_name LIKE '%$a%'"; 
   $res  = mysql_query($sql);   
   $result = mysql_fetch_array($res); 

   if($result >=1){
       header("location:become-postie-vehicle.php");
       die();   
   }else{
       header("location:city-unavailables.php");
       die();
   }

where $a = $_POST['address'] ; is input field name (Where it is use for search) so please let me know how can I match the city from my database?my database is given below

CREATE TABLE IF NOT EXISTS `tbl_city` (
`id` int(100) NOT NULL,
 `city_name` varchar(100) NOT NULL
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;


  INSERT INTO `tbl_city` (`id`, `city_name`) VALUES
  (1, 'london');

Now please help me to find out solution. Remember i have used REGEXP MATCH() ... AGAINST in $sql already.it is most challenging ever.
Anyone have Solution???

If you're always going to have the same format of the city with a comma followed by something, you could just write the query with a substring_index to split on the comma. If it isn't always going to be that way, then of course you wouldn't be able to do that.

SELECT * FROM tbl_city WHERE city_name LIKE SUBSTRING_INDEX('London, United Kingdom', ',', 1);

This splits the string on the first comma, and uses the value of 'London' in the search.

OR

You could split the string in PHP prior to running the query.

commented: great you have done it thanks +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.