Select items from various sources, and order by da

2019-03-06 23:03发布

问题:

I would like to achieve the followings but is having difficulties: 1) Select an item from either one of two query (item_title, or item__keywords), in the sense that when the user searches it will see if the items is found within item_title, or item_keywords. 2) Order the search by most recent date

Below is my first attempt, but it does not seem to work properly:

$get_item = "select * from items where item_title OR item_keywords like '%search_query%' ORDER BY 'course_date'";
$run_item = mysqli_query($con, $get_item);

回答1:

OR separates whole clauses, not 2 fields. Try this instead:

SELECT * 
    FROM items 
    WHERE item_title LIKE '%search_query%' 
        OR item_keywords LIKE '%search_query%' 
    ORDER BY course_date