简体   繁体   English

MySQL / PHP-显示表格中除单行外的所有行

[英]MySQL / PHP - Display all rows from table except one single row

me again! 又是我!

So I'm wondering what the sequel/php code is to display all the rows in a table except one row. 所以我想知道续集/ php代码将显示表中除一行以外的所有行。 So display row 1, 2, 3 and 4 and every column, but don't display anything to do with row 5. The reason for this is I want to display all users in a user table except the user that is looking at the list itself. 因此,显示第1、2、3和4行以及每一列,但不显示与第5行有关的内容。原因是我想在用户表中显示所有用户,但正在查看列表的用户除外本身。

Checking which user is looking at the list is fine because I can use a variable I set aside called userid which can be used to check it against. 检查哪个用户正在查看列表就可以了,因为我可以使用我预留的一个名为userid的变量,该变量可用于对其进行检查。 I just don't know the SQL terminology I need to use to essentially "select * from table except this row". 我只是不知道我需要用来本质上“从表中选择*而不是该行”的SQL术语。

Any help please? 有什么帮助吗?

有什么问题:

SELECT * FROM `table` WHERE `id` <> 5
SELECT * FROM `users` WHERE `userID` != 5

用当前用户的ID替换5应该可以解决问题。

SELECT * FROM table WHERE NOT user_id = < id >

为什么不只是

 SELECT * FROM table WHERE userid != 'currentUser'

$query = "SELECT * FROM users WHERE userId != $userId" ; $ query =“选择*从用户WHERE userId!= $ userId”;

$userId can contain the user defined id $ userId可以包含用户定义的ID

SELECT *

FROM (SELECT ROW_NUMBER() 

OVER(ORDER BY id) RowNr, id FROM tbl) t

WHERE RowNr BETWEEN 10 AND 20

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM