だから私はここに小さなものを作成しました:
http://sqlfiddle.com/#!2/d7a76/1
そして、それは私が望むことをしますが、実際の PHP に適用すると機能しません。読み込み時に、HTML ページは「bundle_lanes」SQL データベースにあるものからドロップダウンにすべてのケーブル番号を表示します。しかし最近、私のクライアントは、ケーブル番号がデータベース「cabletypes」に既に存在する場合、ケーブル番号を非表示にすることを望んでいます。したがって、正確なケーブル番号の一致を検索し、両方のテーブルに存在する場合は表示しないように SQL に指示する方法が必要です。私は何を間違っていますか?それはsqlfiddleで動作します。エラーはありません。cableNumbers.php と空のドロップダウン ボックスを実行すると、結果が空白になります。
HTML (index.php)
<body onload="cable_numbers(); company_name();">
<select id="cable_no" onchange="update_section_no();" return false;>
<option value="">Cable Number</option>
</select>
</body>
ジャバスクリプト
//Set Cable Numbers in DropDown
function cable_numbers() {
$.ajax({
url: './php/cableNumbers.php',
dataType: 'json',
success: function(mydata) {
var combo = document.getElementById("cable_no");
while (combo.firstChild) {
combo.removeChild(combo.firstChild);
};
var option = document.createElement("option");
for (var i = 0; i < mydata.length; i++) {
option = document.createElement("option");
option.text = mydata[i]['cable_no'];
option.value = mydata[i]['cable_no'];
try {
combo.add(option, null); //Standard
} catch (error) {
combo.add(option); // IE only
}
};
section_numbers();
}
});
};
PHP cableNumbers.php (SQL クエリが存在する場所)
$sql = "SELECT DISTINCT cable_no FROM bundle_lanes
WHERE (cable_no) NOT IN (SELECT cable_no FROM cabletypes)
ORDER BY cable_no ASC";
$result = mysql_query($sql) or die ('Error'.mysql_error());
// If DB query successful then send data to calling routine.
if (mysql_num_rows($result) >= 1)
{
while ($row = mysql_fetch_array($result)) {
$array[] = $row;
}
print json_encode($array);
}