首页 > 解决方案 > 在颤振中将表名传递给 getData.php

问题描述

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

我想要的是,当我根据 getData.php 中提到的查询调用 http.get 从特定表中获取所有数据时,还必须有一个过程将该表名发送到该 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);
?>

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

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

标签: phpmysqlflutterphpmyadmin

解决方案


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

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

推荐阅读