Php 按钮提交,从数据库中获取其他按钮

Php 按钮提交,从数据库中获取其他按钮,php,Php,这是我目前的代码: require_once 'functions.php'; // makes the connection to the server to get the state button names $query = "SELECT state FROM state"; $result = $connection->query($query); if ($result === false) { // error mssg echo "<p>

这是我目前的代码:

require_once 'functions.php';
// makes the connection to the server to get the state button names
  $query  = "SELECT state FROM state";
  $result = $connection->query($query);
  if ($result === false) {
  // error mssg
  echo "<p>Query fout.</p>";
}

  // button of the state gets the buttons of the city
  if (isset($_POST['state'])) $state = $_POST['state']; {
  query  = "SELECT city FROM city='$cityid'";
  $result = $connection->query($query);
} if ($result === false) {
  // geef nette foutmelding
  echo "<p>Query fout.</p>";
 }
<?php 

//gives the result to Submit html
while ($row = $result->fetch_assoc()) {

echo "<input type ='submit' name='provincie' value='".$row['provincie']."'>";

}
$result->free();
?>
</for
require_once'functions.php';
//与服务器建立连接以获取状态按钮名称
$query=“从状态中选择状态”;
$result=$connection->query($query);
如果($result==false){
//误差mssg
回声“查询fout.

”; } //国家的按钮得到城市的按钮 如果(isset($_POST['state']))$state=$_POST['state'];{ query=“从城市中选择城市='$cityid'; $result=$connection->query($query); }如果($result==false){ //geef nette熔接 回声“查询fout.

”; }
您需要单独执行查询结果,因此应该有两个while语句

这不是最好的办法,但我有一个办法:

      require_once 'functions.php';
      $query  = "SELECT state FROM state";
      if($query->num_rows > 0){
                    while($row= $result->fetch_assoc()) {

                      echo "<input type ='submit' name='provincie' value='".$row['provincie']."' onclick="sendVal(this.value)" >";

                    }   
      }

<script type="text/javascript">
function sendVal(item) {    
    document.cookie="city=" + item + ";";
    location.reload();
}
</script>

<?php 
    if(!is_null($_COOKIE['city'])){     
        $retrievedcities= "SELECT city FROM city WHERE city ='".$_COOKIE['city']."'"; 
        $con->query($retrievedcities);
       while ($row = $result->fetch_assoc()) {
              echo "<input type ='submit' name='citybut' value='".$row['city']."'>";
         }

 unset($_COOKIE['city']);
  }
require_once'functions.php';
$query=“从状态中选择状态”;
如果($query->num\u rows>0){
而($row=$result->fetch_assoc()){
回声“;
}   
}
函数sendVal(项){
document.cookie=“city=“+item+”;”;
location.reload();
}

这个代码部分工作吗?这似乎应该是错误的
if(isset($\u POST['state']))$state=$\u POST['state'];{
。我想你应该用AJAX来做的事情。发送一个请求,获取响应,根据初始返回的数据发送另一个请求,对吗?是的,它不需要:“//状态按钮获取…$result=$connection->query($query);”。我把代码放在上面,以显示我已经尝试过的内容。我尝试了很多谷歌,但我不知道该问谷歌什么来解决我自己的问题。因为我不只是在寻找一个脚本来复制和过去。