sql语句从数据库限制中选择不起作用

时间:2016-05-29 03:42:04

标签: php mysql

我有一个问题,即我的限制声明没有工作我希望从数据库中选择内容并将节目内容限制在40只但它没有工作

这是我的带有PHP代码的SQL语句

$chatroomID=$_GET['chatroomID'];
$userID = $_SESSION['id'];

$sql="SELECT * FROM chatroom_chat WHERE chatroom_id ='$chatroomID'";
$result1 = mysqli_query($connection, $sql) or die(mysqli_error($connection));

    while ($row = mysqli_fetch_array($result1)) {
    $chat = $row['chat_id'];

    $sql3 ="SELECT * FROM (
    SELECT * FROM chat WHERE id = '$chat' ORDER BY id DESC LIMIT 0,40
    ) sub
    ORDER BY id ASC ";

    $getChatData = mysqli_query($connection,$sql3) or die(mysqli_error($connection));

   /*here have statement to get username*/

    while($row3 = mysqli_fetch_array($getChatData)) {
        echo "<div>all content</div>";
    }

}

我的代码有任何语法错误吗?我不知道为什么它没有工作

1 个答案:

答案 0 :(得分:-1)

SELECT * FROM (
        SELECT * FROM chat WHERE id = '$chat' ORDER BY id DESC LIMIT 40
        ) sub
        ORDER BY id ASC