只是我想id
单独处理列的值,以便在 mySQL 的隐藏字段中使用它。但是当我获取 name,surname,id
它们出现在搜索文本字段中时,也id
出现了值。我只想在隐藏字段的值区域中使用 id 。只有姓名,姓氏必须出现在文本字段中。如何立即将 id 的值设置为隐藏字段?
自动完成.php
<?php
include 'config/db.connect.php';
$return_arr = array();
if (isset($_GET['term'])){
try {
$stmt = $db->prepare('SELECT id,user_username,name,surname FROM user WHERE name LIKE :receiver or surname LIKE :receiver or user_username LIKE :receiver');
$stmt->execute(array('receiver' => '%'.$_GET['term'].'%'));
while($row = $stmt->fetch()) {
$return_arr['name'] = $row['name'];
$return_arr['surname']= $row['surname'];
$return_arr['id']= $row['id'];
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo json_encode($return_arr);
}
?>
我的表单页面中的脚本
<script type="text/javascript">
$(function() {
//autocomplete
$("#receiver").autocomplete({
source: "autocomplete.php",
minLength: 1,
select: function(event, ui) {
$("#receiver_id").val(ui.item.value);
}
});
});
</script>
形式
<form action="action_send_message.php" method="POST" >
<label for="receiver">Receiver</label>
<input type="text" name="receiver" id="receiver" placeholder="Receiver" class="span12" />
<input type="hidden" name="receiver_id" id="receiver_id" value=""/>
<textarea id="messagebody" name="message_body" class="wysihtml5 span12" rows="5" placeholder="Mesajınızı Yazın"></textarea>
<button type="submit" class="btn btn-large color-10">Gönder</button>
</form>