我有选择框:
<?php $players = select("`id`,`name`","`players`","`id`","ASC")->fetchAll(PDO::FETCH_ASSOC); ?>
<select id="player_select" name="player" class="form-control">
<option value="0">--Oyunçu seçin--</option>
<?
foreach ($players as $player) {
echo '<option value="'.$player['id'].'">'.$player['name'].'</option>';
}
?>
</select>
I want to fill text boxes with data about selected item. I have code:
$(function(){
$('#player_select').change(function(){
var selections = $("#player_select :selected");
$.ajax({
url: selected_option,
type: 'post',
cache: false,
success: function(return_data) {
$('#second_select').html(return_data);
}
var html = '';
$.each(selections,function(i,item){
html += ':<div class="form-group"><label class="control-label col-sm-2">Ad</label>' +
'<div class="col-sm-10">' +
'<input type="text" id="name" name="name" class="form-control" value="<?= $playerfetch['name'];?>" readonly>' +
'</div></div><div class="form-group">' +
'<label class="control-label col-sm-2">Kod</label>' +
'<div class="col-sm-10">' +
'<input type="text" id="code" name="code" class="form-control" value="<?= $playerfetch['code'];?>" readonly>' +
'</div></div>'+
'<div class="form-group"><label class="control-label col-sm-2">Doğum tarixi</label>' +
'<div class="col-sm-10">' +
'<input type="text" id="birthday" name="birthday" class="form-control" value="<?= $playerfetch['birthday'];?>" readonly>' +
'</div></div>;
})
$('#divFileInput').html(html);
})
})
我从数据库中获取用户信息的功能是:
$playerfetch = prepare("*","`players`","`id`=?",[$_GET['player_select']])->fetch(PDO::FETCH_ASSOC);
问题: 我不知道如何将选定的项目从选择框传递给我的功能。现在,它总是显示最后的ID和相关信息。