dougong2005 2015-09-06 09:26
浏览 91
已采纳

在PHP中更新变量而不刷新

I need to update a variable named $count (in the below code) automatically. When my database update, $count be update immediately because i need to use value of $count in android app so i can't refresh count.php file every time.

<?php
$con=mysql_connect("","","");
mysql_select_db("u607509006_bd1",$con);

$query = "select * from content where status='a'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
echo $count;
mysql_close($con);
?>
  • 写回答

1条回答 默认 最新

  • douyue8364 2015-09-06 10:18
    关注

    Just use a Jquery Ajax Request on the client side like so:

    $.ajax({
      url: "path/to/code/file.php" // change this to your path to your code
    }).done(function(data) {
      // This is executed after the ajax request is complete
      // data should be the updated value. You can also return other data // types e.g. JOSN
      $('#counter').text(data);
    });
    

    JS Fiddle Example: https://jsfiddle.net/anik786/nvkdLhv2/2/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题