I want to search for data from the database using MySQL like
query
here is my query:
global $wpdb;
if($_GET['search']){
$search = $_GET['search'];
}
else{
$search = $_GET['searchtop'];
}
$search_details = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM
tbl_brand,
tbl_generic,
tbl_therapeutic_area,
tbl_drug
WHERE
tbl_brand.generic_id = tbl_generic.generic_id
AND
tbl_brand.therapeutic_area_id =
tbl_therapeutic_area.therapeutic_area_id
AND
tbl_brand.brand_id = tbl_drug.brand_id
AND
tbl_brand.brand_name LIKE '%$search%'",""
),ARRAY_A
);
My data is like DUET
{upper case letter} in database I search using lower case duet
It returns no results found
But when I search Duet
its found.
See results when I search using duet
See results when I search using Duet
And If I use this SQL query manually in phpmyadmin its result found.
So that reason I want to get data using a lower or upper case!
2
Answers
I am using properly prepare query like:
And Its works.
Convert your search string in lower case
Then use LOWER() function to convert your field value in lower case and query like this :