I recently managed to create a mysqli search engine in php. The problem is that if you find more than 1 result simply put the same user id and name.
if(!empty($_POST)){
if(isset($_POST["username"])){
if($_POST["username"] !=""){
include "conexion.php";
$buscar = $_POST["username"];
$sql1= "SELECT * FROM usuarios WHERE Username LIKE '%$buscar%'";
$query = $con->query($sql1);
if($row = mysqli_fetch_array($query)){
echo "Resultados para: $buscar";
do {
?>
<br>
<br>
(ID: <?php echo $row['ID']; ?>) - <?php echo $row['Username']; ?>
<?php
}
while (mysqli_fetch_array($query));
}
else
{
echo "No se encontraron resultados para: $buscar";
}
}
}
Suppose I enter "hello" and in the database there are 3 registered users with the name "hello" "hello1" "hello2", the code would give me this:
Resultados para: hola
(ID: 2) - hola
(ID: 2) - hola
(ID: 2) - hola
Instead of giving me something like this
(ID: 2) - hola
(ID: 3) - hola1
(ID: 4) - hola2
I hope you can understand, thank you already.