我有这张table。
name | total
chris | 5
jan | 3
bob | 2
eric | 4
克里斯和简是用这个代码选出来的
$query = " select * from table where name = '$given_name' ";
// &given_name = result from another query
我想将查询结果存储到一个变量中。
while($row=mysql_fetch_assoc($query)){
$result = $row['name'];
} // i want to store both chris and jan to $result
然后我将使用查询的结果进行另一个查询。我想选择剩下的名字。不是第一个查询中的。我不希望chris和jan被选中,因为它存储在$result中
select * from table where name != $result ;
但$result中只存储了一个名称。我希望它们都存储在$result中。
3条答案
按热度按时间o7jaxewo1#
你可以用
FIND_IN_SET
看看这些名字以前有没有被取过。首先你需要$result
所有名称的数组:然后可以编写查询以排除
$result
:46scxncf2#
假设您不知道结果集的名称,您可以简单地(a)从结果集中选择前两个名称,(b)将它们串联在一个字符串中,最后(c)使用“not in”作为查询参数。
快乐的编码!
xu3bshqb3#
您可以使用下面的数据库查询来排除
chris
以及jan
: