[英]How to get results from php to html <select> option?
i have a select option in index.html , i want to get result from mySQL via php, but how to get the result from php ,and add results to html automatically我在 index.html 中有一个选择选项,我想通过 php 从 mySQL 获取结果,但是如何从 php 获取结果,并自动将结果添加到 html
index.html:索引.html:
<form action="get.php" method="post" >
<select>
<option class="rm" value="trap"><get results from php></option>
.............
</select>
</form>
If you could show me a working example which does that, or may be any similar idea, it would be good.如果您可以向我展示一个可以做到这一点的工作示例,或者可能是任何类似的想法,那就太好了。
I don't really understand what you mean.我真的不明白你的意思。 But did you mean something like this:
但是你的意思是这样的吗:
<html>
<body>
<select>
<?php
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
include "$root/config.php";
$something1 = "something1";
$something2 = "something2";
$stmt = $pdo->prepare('SELECT DISTINCT from_mysql FROM customers WHERE something1 = :something1 AND from_mysql != :something2 ORDER BY from_mysql');
$stmt->execute(array(':something1' => $something1, ':something2' => $something2));
$results = $stmt->fetchAll();
if (empty($results)) {
echo 'Error: Please contact technical support!';
} else {
foreach( $results as $row ) {
echo "<option>".$row['from_mysql']."</option>";
}
}
?>
</select>
</body>
</html>
PS You'll have to use index. PS 你必须使用索引。 php
php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.