dongpi9494 2014-02-17 04:10
浏览 9
已采纳

使用jquery控制php页面上数据库结果的限制

Is there anyway to control the limit of entries from a database using jquery.


I have the PHP Data.php:

mysqli_query($con,"(select * from social order by id desc limit 30) order by id asc");

But I want to be able to edit the limit 30 and use $.get() to request the php again on calling a click function in jquery. Is this possible?


The $.get():

 $.get("Data.php", function (data3) {
     $(".data").html(data3);
 });

My code now looks like this:

Data.php:

$limit_amt = mysqli_real_escape_string($_GET['limit']);

$result = mysqli_query($con,"(select * from social order by id desc limit ".$limit_amt.") order by id asc");

while($row = mysqli_fetch_array($result))
  {
      echo "<tr class='border_bottom'>";
      echo "<th scope='col'>";
      echo "<div align='left'><span class='name'>".$row['name']."</span></div><br />";
      echo "<span class='text'>".$row['comunicate']."</span><br />";
      echo "<div align='right'><span class='time'>".$row['date']."</span></div>";
      echo "</th>";
      echo "</tr>";

  }

Index.php:

$.get("Data.php",{ limit: 40}, function (data3) { .
         $(".data").html(data3);

    });
  • 写回答

2条回答 默认 最新

  • dongnanman9093 2014-02-17 05:35
    关注

    In your $.get():

    //#btn would represent an HTML element like <input type="button" id="btn">
    $("#btn").click(function(e){
        // I have given a static value here but you can change it to a variable or 
        // however you want to pass
        $.get("Data.php",{ limit: 40}, function (data3) { .
             $(".data").html(data3);
        });
    }
    

    In your Data.php:

    //Fetching the value and saving into a variable
    $limit_amt = mysqli_real_escape_string($_GET['limit']);
    //Using the fetched value to change the limit amount
    mysqli_query($con,"(select * from social order by id desc limit ".$limit_amt.") order by id asc");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值