我是初学者,有点困惑,如何从数据库中获取当前位置的信息。举一个例子,在DATABASE中:三行..id(主键),用户ID和信息以及几乎400 id的数据。
现在假设用户输入用户名:abc,它位于id的第120位。
我希望在第120个位置后显示所有id s and userid
s。说从第121个id到第400个id。
我为此创建了一个代码,但它根本不起作用。请提前帮助和谢谢。
代码:
<?php
if(isset($_POST['submit']))
{
$userid=$_POST['refuserid'];
$sql = "SELECT id, userid, fullname FROM personal WHERE > (select id from personal where userid='$userid')";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result))
{
$i=1;
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" .$row["id"]. "</td>";
echo "<td>" .$row["userid"]. "</td>";
echo "<td>" .$row["fullname"]. "</td>";
$i++;
}
} else {
echo "0 results";
}
}
?> <form action="" method="post">
<input type="text" name="refuserid" />
<input type="submit" name="submit" value="Submit" />
</form>
连接:
<?php
$conn=mysqli_connect("localhost","root","", "gold99");
?>
感谢。
答案 0 :(得分:0)
试试这个:
SELECT p.id, p.userid
FROM personal p
WHERE EXISTS (SELECT 1
FROM personal p1
WHERE p.id > p1.id AND p1.userid = 'abc'
);
答案 1 :(得分:0)
尝试以下代码
$sql = "SELECT id, userid FROM personal where id > (SELECT id FROM personal where userid = 'abc')";
$data = mysqli_query($conn,$sql);
答案 2 :(得分:0)
尝试此查询:
$ID = $_POST['id'];
$sql = "SELECT id, userid FROM personal WHERE id > (SELECT id FROM personal WHERE userid = '{$ID}')";
$data = mysqli_query($conn,$sql);
答案 3 :(得分:0)
尝试此join
查询
$sql = "SELECT a.id, a.userid, a.fullname FROM personal as a INNER JOIN personal as b ON a.id > b.id AND b.userid = 'abc'";