从各种来源选择项目,并按日期排序 [英] Select items from various sources, and order by date

查看:74
本文介绍了从各种来源选择项目,并按日期排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想达到以下目的但有困难:
1)从两个查询(item_title或item__keywords)中选择一个项目,这意味着当用户搜索它时会看到项目在item_title或item_keywords中找到。
2)根据最近的日期排序搜索

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);


推荐答案

OR 分隔整个子句,而不是2个字段。试试这个:

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

这篇关于从各种来源选择项目,并按日期排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆