在 flutter 中将表名传递给 getData.php

pass the tablename to getData.php in flutter

我正在使用 MySQL 制作一个 flutter 应用程序。在主页中,我有一个列表视图,如下所示。对于列表视图中的每个项目,数据库具有唯一的 table。

我想要的是,当我调用 http.get 以根据 getData.php 中提到的查询从特定 table 获取所有数据时,还必须有一个过程将 table 名称发送到 php 文件,以便完成查询。

这是getData.php:

<?php
include 'conn.php';
$Table = $_POST['Tablename'];
$query = "select * from ".$Table;
$data = mysqli_query($conn, $query);
$result = array();
while ($row = mysqli_fetch_array($data)) {
    $result[] = $row;
}
echo json_encode($result);
?>

这是我为获取数据而编写的代码。我可以写什么来将 tablename 发送到 getData.php:

  Future<List> getQue() async {
    var response = await http.get(url);
    return json.decode(response.body);
  }

为您的 http 调用使用 post 而不是 get

Future getQue() async {
  var response = await http.post(url, body:{'Tablename': your-table-name});
  return json.decode(response.body);
}