PHP, SQL limit query by php variable

前端 未结 2 1221
温柔的废话
温柔的废话 2021-01-17 03:00

PHP code defining variable sqlshowvalue

$sqlshowvalue = 5;
if(isset($_POST[\'showmore\'])) {
     $sqlshowvalue += 5;
}

So I connect to my

相关标签:
2条回答
  • 2021-01-17 03:16

    Have you tried making

    $result = mysqli_query($conn,"SELECT * FROM comments ORDER BY id DESC limit '$sqlshowvalue'");
    

    to

    $result = mysqli_query($conn,"SELECT * FROM comments ORDER BY id DESC limit ".$sqlshowvalue);
    
    0 讨论(0)
  • 2021-01-17 03:29

    Remove '' use only $sqlshowvalue:-

    $result = mysqli_query($conn,"SELECT * FROM comments 
    ORDER BY id DESC limit $sqlshowvalue");
    

    for integer value no need of ''

    0 讨论(0)
提交回复
热议问题