Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将结果从php转换为html选项?_Php_Html - Fatal编程技术网

如何将结果从php转换为html选项?

如何将结果从php转换为html选项?,php,html,Php,Html,我在index.html中有一个select选项,我想通过php从mySQL获取结果, 但是如何从php中获取结果,并将结果自动添加到html中呢 index.html: <form action="get.php" method="post" > <select> <option class="rm" value="trap"><get results from php></option> .............

我在index.html中有一个select选项,我想通过php从mySQL获取结果, 但是如何从php中获取结果,并将结果自动添加到html中呢

index.html:

<form action="get.php" method="post" >
    <select>
    <option  class="rm" value="trap"><get results from php></option>
.............
    </select>
 </form>

如果你能给我一个这样做的工作示例,或者是任何类似的想法,那就太好了。

我真的不明白你的意思。但你的意思是这样的吗:

<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>

另外,您必须使用index.php

将其重命名为index.php,然后直接在页面上添加您的php。但是重命名为index.php,我的网站布局将发生更改不,它不会更改您的布局。扩展名让文件知道也可以读取php,否则它将不知道它的php语言,但是扩展名已经验证了html/css和。php也可以使用phpand javascriptI。我不理解您的问题。您想从db中的表中获取数据,并想在下拉列表中显示selecterror_reporting0@ini_设置“显示错误”,0;只是不!永远不要这样做,尤其是在开发网站上!