有一种简单的方法可以在一个中执行这两个查询:
$name = 'somename';
$id = mysql_result(mysql_query('SELECT id FROM table WHERE name = $name'));
$next_id = mysql_result(mysql_query('SELECT id FROM table WHERE id > $id ORDER BY id ASC LIMIT 1, 1'));
由于
答案 0 :(得分:0)
获取ID的子查询,然后> =所选ID,然后限制2
SELECT id FROM table WHERE id >= (SELECT id FROM table WHERE name = '$name') ORDER BY id ASC LIMIT 2
答案 1 :(得分:0)
你试过吗?
$next_id = mysql_result(mysql_query('SELECT id FROM table WHERE id > (SELECT id FROM table WHERE name = $name LIMIT 1,1) ORDER BY id ASC LIMIT 1, 1));