このコードを実行するには、より良い方法がありますか。 #BA_customerを選択してフォームを選択すると、選択したクライアントのアドレスで2番目のメニューが表示されます。また、顧客の選択に基づいてdeptドロップダウンを表示する必要があります。私が持っているコードは、顧客が2つの別々のステートメントで2回渡されているところで競合を引き起こしていると思います。これを行う正しい方法は何ですか?多くのおかげで結果に矛盾が生じるjQueryコード
<script language="javascript" type="text/javascript">
$(function() {
$("#BA_customer").live('change', function() { if ($(this).val()!="")
$.get("../../getOptions.php?BA_customer=" + $(this).val(), function(data) {
$("#BA_address").html(data); });
});
});
</script>
<script language="javascript" type="text/javascript">
$(function() {
$("#BA_customer").live('change', function() { if ($(this).val()!="")
$.get("../../getDept.php?BA_customer=" + $(this).val(), function(data) {
$("#BA_dept").html(data); });
});
});
</script>
+++++++ dept.phpコード+++++++++++++++++++++
$customer = mysql_real_escape_string($_GET["BA_customer"]); // not used here, it's the customer choosen
$con = mysql_connect("localhost","root","");
$db = "sample";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$query_rs_select_dept = sprintf("SELECT * FROM departments where code = '$customer'");
$rs_select_dept = mysql_query($query_rs_select_dept, $con) or die(mysql_error());
$row_rs_select_dept = mysql_fetch_assoc($rs_select_dept);
$totalRows_rs_select_dept = mysql_num_rows($rs_select_dept);
echo '<label for="dept">Select a Department</label>'.'<select name="customerdept">';
echo '<option value="">Select a Department</option>';
while ($row_rs_select_dept = mysql_fetch_assoc($rs_select_dept))
{
$dept=$row_rs_select_dept['name'];
echo '<option value="dept">'.$dept.'</option>';
}
echo '</select>';
++ ++ SOLUTION +++++++++++++
mysql_select_db($db, $con);
$query_rs_dept = sprintf("SELECT * FROM departments where code = '$customer'");
$rs_dept = mysql_query($query_rs_dept, $con) or die(mysql_error());
$totalRows_rs_dept = mysql_num_rows($rs_dept);
echo '<label for="dept">Select a Department</label>'.'<select name="customerdept">';
echo '<option value="">Select a Department</option>';
while ($row_rs_dept = mysql_fetch_assoc($rs_dept))
{
$dept=$row_rs_dept['name'];
echo '<option value="dept">'.$dept.'</option>';
}
echo '</select>';
は、最初の$ row_rs_select_dept = mysql_fetch_assoc($のrs_select_dept)を削除します。スクリプトからそれは動作します。他の魂がこのような問題に助けを必要とする場合に備えて、単にポストされた解決策。
これはtypo: 'value =" dept ">'の代わりに 'value =" '。$ dept。' "'ですか? – marc
私はそれを試みましたが、何の違いもありませんでした。その上、その価値は成功のコレクションのためだけです – bollo