0

我有一个简单的查询:

$user_id = $_SESSION['user_id'];

SELECT *  FROM pages WHERE user_id IN($user_id);

pages 表中的字段 user_id 具有以下格式 1,3,5,... 它包含多个 user_id

我需要的是根据登录的 user_id 选择所有行。上述尝试不起作用,它只拿起第一个数字。

4

1 回答 1

2

您需要使用find_in_set()

select *
from pages
where find_in_set(user_id, $user_id) > 0;

或者,您可以构造 SQL,使其具有字符串中的值。就像是:

select *
from pages
where user_id in (".$user_id.")"
于 2013-07-14T17:22:56.967 回答