I have a searching feature on my website which searches and displays data!
My db structure is fairly simple. I have a table in which there are multiple columns but I want to fetch data on the basis of two columns, now I have a query that takes the user search as a parameter. What I want to do, is to search in two specific columns and return the data!
Here is my query:
$key=$_GET['key'];
$key=str_replace("-"," ",$key);
$query="
select rand_id
, title_short
, color
, path
, category
from data
where title_full LIKE CONCAT('%',?,'%')
";
$stmt = $db->prepare($query);
This query is fetching data from one column title_full
, but what I want to do is to add another column here named size
so that it searches from both columns.
Any help?
done it myself i just added an OR condition at the end
$key=$_GET['key'];
$key=str_replace("-"," ",$key);
$query="select `rand_id`,`title_short`,`color`,`path`,`category` from `data` where `title_full` LIKE CONCAT('%',?,'%') OR `size` LIKE CONCAT('%',?,'%')";
$stmt = $db->prepare($query);
if($stmt){
$stmt->bind_param("ss",$key,$key);
$stmt->bind_result($rand_id,$title, $color, $path, $category);
$stmt->execute();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.