如何使用html主体中的select选项值作为php sql语句同一页面中的变量

如何使用html主体中的select选项值作为php sql语句同一页面中的变量,php,html,mysql,sql,Php,Html,Mysql,Sql,正如我所理解的那样,PHP过程是自上而下的。因此,在语句使用变量之前,必须先定义变量 但是,当select值更改为下面的select值时,我如何使在主体中定义为变量的select选项值可以用于上面的语句,而select值也应该自动更改范围 例如 <?php // connect to MySQL $conn1 = dbConnect('admin'); // prepare the SQL query $sql = "SELECT * FROM contract WHERE

正如我所理解的那样,PHP过程是自上而下的。因此,在语句使用变量之前,必须先定义变量

但是,当select值更改为下面的select值时,我如何使在主体中定义为变量的select选项值可以用于上面的语句,而select值也应该自动更改范围

例如

    <?php

 // connect to MySQL
$conn1 = dbConnect('admin');

// prepare the SQL query
$sql = "SELECT * FROM contract WHERE cont_num = '$contract_number'";

// submit the query and capture the result
$micko = $conn1->query($sql) or die(mysqli_error());

?>

施工客户:
账号:
建设量:
已创建:
经纪人:

因为php是一种基于服务器的脚本语言,所以必须对php文件进行异步连接。例如,您可以使用AJAX来实现这一点


将所选值作为get或post参数加载php文件。然后,您可以在php文件中输出sql语句的结果,并在ajax引擎中获取该值。

听起来像是jqueryuse ajax的一项工作,即重新加载并使用select选项变量。有没有办法在同一页面上传递该值?如果你有你的php和html在同一页?或者只需在不同页面上发布并捕获为$_POST['value']?您可以在同一页面上执行此操作,但必须在代码周围使用
if
语句,在该语句中检查是否设置了$_POST['value']。但我建议用一个外部页面来实现这一点。它更简单、更清晰。
<table>

<?php
while ($ayanda = $micko->fetch_assoc()) {
?>

<tr>
<select name = "contract_no">

<!--these select options are derived from a different sql statement as the rest of the  table-->

<?php
while ($row = $chuchu->fetch_assoc()) {
?>
<option><?php echo $row['cont_num']; ?></option>
<?php  $contract_number = '<option value="'.$row.'">'.$value.'</option>';?> 
<?php } ?>
</select>
<td></td>
<td><strong>Contruct Customer:</strong></td>
<td><?php echo $ayanda['cont_custm']; ?></td>
</tr>


<tr>
<td><strong>Account Number:</strong></td>
<td><?php echo $ayanda['accnt_num']; ?></td>
<td></td>
<td><strong>Contruct Volume:</strong></td>
<td><?php echo $ayanda['cont_vol']; ?></td>
</tr>


<tr>
<td><strong>Created:</strong></td>
<td><?php echo $ayanda['created']; ?></td>
<td></td>
<td><strong>Broker:</strong></td>
<td><?php echo $ayanda['broker']; ?></td>
</tr>
<?php } ?>
</table>