据我了解 PHP 过程从上到下的顺序。因此,您必须在使用它的语句之前定义一个变量。
但是,当下面的选择值更改也应该自动更改范围时,我如何使在我的主体中定义为变量的选择选项值可用于上面的语句?
例子。
<?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());
?>
在我的 html 中,变量 contract_number 被定义为下表中选择选项的变量。我怎样才能将它传递回我的 sql 语句的顶部。i also want the table to reload automatically when the select value changes as the variable value changes so it returns correct info. 或者如果你有更好的方法我可以做到这一点,请帮忙。
<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>