MySQL / PHP - 显示表中除一行之外的所有行
me again!
So I'm wondering what the sequel/php code is to display all the rows in a table except one row. 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.
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. I just don't know the SQL terminology I need to use to essentially "select * from table except this row".
Any help please?
我再来一次! p>
所以我想知道续集/ php是什么 代码是显示除一行之外的表中的所有行。 因此,显示第1,2,3和4行以及每一列,但不显示与第5行有关。原因是我想显示用户表中的所有用户,但查看列表的用户除外 检查哪个用户正在查看列表是正常的,因为我可以使用一个名为userid的变量,可以用来检查它。 我只是不知道我需要使用的SQL术语基本上“从表中选择*除了这一行”。 p>
请帮忙吗? p> div>
What's wrong with:
SELECT * FROM `table` WHERE `id` <> 5
SELECT * FROM `users` WHERE `userID` != 5
Replacing 5 with the current user's ID should do the trick.
SELECT * FROM table WHERE NOT user_id = < id >
Why not just
SELECT * FROM table WHERE userid != 'currentUser'
$query = "SELECT * FROM users WHERE userId != $userId" ;
$userId can contain the user defined id
SELECT *
FROM (SELECT ROW_NUMBER()
OVER(ORDER BY id) RowNr, id FROM tbl) t
WHERE RowNr BETWEEN 10 AND 20