【问题标题】:pass variable though URL for getting JSON通过 URL 传递变量以获取 JSON
【发布时间】:2017-12-24 15:36:42
【问题描述】:

我有一个应用程序,它从服务器加载数据并在文本视图中发布该数据,但有一个场景

      <?php

     define('HOST','xxxxxx');
     define('USER','xxxxxxx');
     define('PASS','xxxxx');
     define('DB','xxxxxxx');



     //Connecting to Database
      $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

      $sql = "select * from Leaderboard where email='test@test.com'";

      $res = mysqli_query($con,$sql);
      $result = array();

        while($row = mysqli_fetch_array($res)){
        array_push($result,
        array('name'=>$row[1],
         'rank'=>$row[2],
         'accuracy'=>$row[3]));
          }
        echo json_encode (array("list"=>$result));


        mysqli_close($con);

         ?>

这是我的 PHP 文件,它提供了这样的 JSON

        {"list":[{"name":"Vipul S","rank":"1","accuracy":"80"}]}

我很容易使用 volley 库将这些值输入到我的 android 应用程序中,但问题是我需要一些东西来使该电子邮件变量动态化,因为我从用户电话获取用户电子邮件,所以我需要通过一个变量将变量传递给 PHP我的 android,所以我有没有机会通过我用 android 编写的 URL 传递它

 my URL is: "http://thehostels.in/judgement_files/myleaderboard.php"

所以我可以通过将由 PHP 文件获取的 URL 中的电子邮件通过

  $email=$_GET['userEmail'];

最后我想要的是 JSON 应该根据由于 URL 而改变的电子邮件而改变,我希望我说得通

【问题讨论】:

    标签: php android json


    【解决方案1】:

    您可以在 URL 中传递电子邮件 ID 为

    http://thehostels.in/judgement_files/myleaderboard.php?userEmail=test@test.com
    

    你可以在PHP中使用这个参数,如下所示

    $email = $_GET['userEmail'];
    $sql = "select * from Leaderboard where email='$email'";
    

    出于安全原因,您应该对电子邮件 ID 使用适当的验证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-03
      • 2015-04-06
      • 1970-01-01
      • 2011-09-25
      • 2016-09-30
      相关资源
      最近更新 更多