duanjuan3931 2013-09-09 12:17
浏览 89

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

As i understand PHP process from top to bottom that order. hence you have to define a variable before the statement using it.

But how would i make a select option value defined as a variable in my main body available for my statement above when the select value changes below should also change the scope automatically?

example.

    <?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());

?>

my html, the variable contract_number is defined as a variable of the select options in the table below. how can i pass it back to the top for my sql statement. i also want the table to reload automatically when the select value changes as the variable value changes so it returns correct info. or if you have a better way i can do this please help.

<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>
  • 写回答

1条回答 默认 最新

  • dsf55s1233 2013-09-09 12:23
    关注

    Because php is a server based script language, you have to do an asynchronus connection to the php file. You can do so with AJAX for example.

    Load the php file with the selected value as get or post parameter. Then you can output the result of the sql statement in the php file and get this value in the ajax engine back.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器