Veran I have an autocomplete textbox, which is autocomplete when I'm writing from a database (Mysql). Well I want you to help me is to select the ID of those elements and go to the profile of each user that I select.
PD: They tell me that I have to create another page that is for the user profiles that I want to see. Apart from mine. Is that true?
HTML
<input type="text" id="busquedas" name="buscar" placeholder="Busca a
alguien">
<div id="nameList"></div>
PHP
<?php
include("conexion.php");
if(isset($_POST['query']))
{
$output = '';
$query = "SELECT * FROM personas WHERE nombre LIKE '%".
$_POST['query']."%'";
$result = mysqli_query($conn, $query);
$output = '<ul class="list-unstyled">';
if(mysqli_num_rows($result) > 0 )
{
while($row = mysqli_fetch_array($result))
{
$output .= '<li><a href="#">'.$row['nombre'].''.$row['apellido'].'</a>
</li>';
}
}
else
{
$output .= '<li>Not found</li>';
}
$output .= '</ul>';
echo $output;
}
?>
JQuery
$(document).ready(function(){
$('#busquedas').keyup(function(){
var query = $(this).val();
if(query != '')
{
$.ajax({
url:"usuarios.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('#nameList').fadeIn();
$('#nameList').html(data);
}
});
}
});
$(document).on('click', '#nameList ul li', function(){
$('#busquedas').val($(this).text());
$('#nameList').fadeOut();
});
});