我想在准备好的声明中使用orderby子句。
以下是我的查询
$stmt = $connect->prepare("SELECT send_stamp,id,receiverid, message, time, status,sentby FROM `chat` WHERE cust_id=?");
$stmt->bind_param('i', $cust_id);
$result=$stmt->execute();
现在,我在此查询中按(asc)添加顺序,按日期或ID对其进行排序。
请帮忙
答案 0 :(得分:0)
你这样做:
$stmt = $connect->prepare("SELECT send_stamp,id,receiverid, message, time, status,sentby FROM `chat` WHERE cust_id = ? ORDER BY id ASC");
$stmt->bind_param('i', $cust_id);
$result=$stmt->execute();
答案 1 :(得分:0)
与普通SQL查询一样:在查询结束时:
$stmt = $connect->prepare(
"SELECT
send_stamp,id,receiverid, message, time, status, sentby
FROM `chat`
WHERE cust_id=?
ORDER BY id DESC"
);
$stmt->bind_param('i', $cust_id);
$result=$stmt->execute();
答案 2 :(得分:0)
您只需要在查询结束时添加,以下是我添加升序子句的示例。
projects = self.leave_not_required_user.projects.filter(is_active=True)
users = []
for project in projects:
project_memberships = project.projectmembership_set.filter(
is_project_manager=True,
user__is_active=True
).all()
for project_membership in project_memberships:
users.append(project_membership.user)
上面的查询将以 $stmt = $connect->prepare(
"SELECT
send_stamp,id,receiverid, message, time, status, sentby
FROM `chat`
WHERE cust_id=?
ORDER BY id ASC"
);
$stmt->bind_param('i', $cust_id);
$result=$stmt->execute();
的升序返回记录,因为我们在id
上使用了order子句。
答案 3 :(得分:0)
通常在mysql的顺序中使用在语句的末尾。像
SELECT send_stamp,id,receiverid, message, time, status,sentby FROM `chat` WHERE cust_id=? order by id
您可以按ID,名称或任何您想要的名称订购该字段的名称。
答案 4 :(得分:0)
$stmt = $connect->prepare("SELECT send_stamp,id,receiverid, message, time, status,sentby FROM `chat` WHERE cust_id=? ORDER BY date ASC");