0

私は大きなジレンマを抱えています。MySQL からフォームにデータを生成しているので、問題は、SQL によって生成された最初の行が 0 であるのに対し、フォームの選択オプションが最初の値を 1 として解釈していることです。問題はありません。このクエリ内から一部のデータを破棄したくない場合。しかし、ここにコードがあります:

<select id="exp_address" name="exp_address" onChange="document.getElementById('exp_city').value = this.options[this.selectedIndex].getAttribute('data-exp_city'); document.getElementById('exp_dist').value = this.options[this.selectedIndex].getAttribute('data-exp_distr'); document.getElementById('exp_address_val').value = this.options[this.selectedIndex].getAttribute('data-exp_city_val')">
<?php 
for($i = 0; $i < $expselnum; $i++){
    $exps_add_id = mysql_result($expsel,$i,'address_id');
    $exps_address = mysql_result($expsel,$i, "address");
    $exps_city = mysql_result($expsel,$i, "city");
    $exps_distr_val = mysql_result($expsel,$i, "district");
    echo "<option value=$exps_add_id data-num=$i data-exp_city = '$exps_city' data-exp_distr = '$exps_distr_val' data_exp_city_val = '$exps_city'>$exps_address</option>";      
}
?>
</select>

生成された HTML コードは次のとおりです。

<select onChange="Here is some JS to change the value of District and City inputs">
<option value=1 data-num=0 data-exp_city = 'BUCURESTI' data-exp_distr = 'Bucuresti' data_exp_city_val = 'BUCURESTI' [selected by default]>Another Address in RO</option><option value=2 data-num=1 data-exp_city = 'OTOPENI-IF' data-exp_distr = 'Ilfov' data_exp_city_val = 'OTOPENI-IF'>Some address in RO</option></select>
<input name="exp_city" type="text" id="exp_city" style="text-align:left;" value="OTOPENI-IF" size="30" readonly="readonly">

option タグの value と data-num att を比較すると、WHY 単位で異なることがわかります。option の最初の値はページ ランディングで選択されますが、都市の入力はクエリからの次の値を示します。どうすればこれを回避できますか? よろしくお願いします。

4

1 に答える 1

0

それほど微妙なことは述べていませんが、私はShrapnelのコメントに同意します. ただし、これで「問題」が解決する可能性があります(ただし、質問はよくわかりません):

for($i = 0; $i < $expselnum; $i++){

への変更:

for($i = 1; $i < $expselnum; $i++){
于 2011-09-12T08:42:53.340 に答える