2016-05-31 8 views
-4

私は、index.htmlをで選択したオプションを持っている私は、PHP経由でMySQLからの結果を取得したい、 しかし、どのようにPHPから結果を取得し、自動的にPHPからhtmlの結果を得る方法<select>オプション?

のindex.htmlをHTMLに結果を追加するには:

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

これを行う、またはそれに類似したアイデアかもしれない実際の例を私に見せてもらえれば、それはいいでしょう。

+3

index.phpに名前を変更して、PHPをページに直接追加します。 – Styphon

+0

しかし、index.phpに名前を変更すると、私のサイトのレイアウトは変更されます – stefansaye

+0

いいえ、レイアウトを変更しません。拡張子はファイルにもphpを読み込ませるようにします。そうでなければ、拡張子はすでにhtml/cssと.phpもphp(とjavascript)で検証されます。 – izk

答えて

0

私は本当にあなたが何を意味するか分かりません。しかし、あなたは次のような意味ですか?

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

P.S.あなたはインデックスを使用する必要があります。 php

+0

を選択してください。 'error_reporting(0);@ini_set( 'display_errors'、0); 'ちょうどいいえ!特に開発用ウェブサイトでこれをしないでください! – Styphon

+0

はい、そうです、申し訳ありません。私はそれを削除した。 –

関連する問題