私は、エンドユーザーがボタンを押したときに行を生成する動的テーブルを持っています。私は入力ボックスでそれを使用しても問題ありませんでした。今私は私のdbからデータを照会するコンボボックスに1つの入力を変更しようとしています。私が知っている問題は、phpコードとともにコンボボックスを動的に追加する方法です。私はどのように私のjsコードと私のPHPコードを混ぜることができます
$(document).ready(function(){
var counter = 2;
$('.add-row').click(function() {
$(".item_form").append(
'<tr><td><input type="text" name="serialnoa[]" placeholder="serial no.' +
counter + '"/></td></tr>'
);
counter++;
});
$('.del-row').click(function() {
if($(".item_form tr").length != 2)
{
$(".item_form tr:last-child").remove();
counter--;
}
else
{
alert("You cannot delete first row");
}
});
});
<!DOCTYPE html>
<html class="no-js" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="_css/inventory.css?v=<?=time();?>">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
<table class="item_form">
<tr>
<th>serial no.</th>
<th>brand<th>
</tr>
<tr>
<td><input type="text" placeholder="serial no.1" name="serialnoa[]"></td>
<td>
\t <select name="show_brands[]">
\t <?php
\t mysql_connect('localhost', 'root', 'adminpass');
\t mysql_select_db('my_db');
\t $sql = "SELECT DISTINCT brand FROM warehouse ORDER BY brand";
\t $result = mysql_query($sql);
\t while ($brand=mysql_fetch_assoc($result)) {
\t \t echo "<option value='".$brand['brand']."'>".$brand['brand']."</option>";
\t }
\t ?>
\t </select>
</td>
</tr>
</table>
<table>
<tr>
\t <td><a href="#" class="add-row"><div>+ Row</div></td>
\t <td><a href="#" class="del-row"><div>- Row</div></td>
\t \t \t \t \t \t \t \t \t
</tr>
</table>
</body>
</html>
することができます;'デフォルトでは非表示の状態でそれをロードし、ボタンのクリックでそれを公開したり、データベースの情報を取得するために、AJAXを使用するか、PHP –
を使用。 –
@JyothiBabuArajaあなたの提案しようとしているものはわかりません。コンボボックスを複製/追加することができます。問題に直面しているオプションと値を取り込むために渡す必要があるクエリです。最善のアプローチは何でしょうか? – bongoloids