Autocomplete/Suggestions/Mysql

Asked

Viewed 89 times

0

Question 1: Does anyone have any functional examples of when someone types in an input pop up suggestions below? preferably coming from a table created in mysql.

Bench: test Table: users (user_id, user_email).

Question 2: In an "option value" how could I sort in descending order? From this:

  <td class="KT_th"><label for="user_id">Nome de Usuário:</label></td>
  <td><select name="user_id" id="user_id">
    <?php
do {  
?>
    <option value="<?php echo $row_Rsmostrar['user_id']?>"<?php if (!(strcmp($row_Rsmostrar['user_id'], $row_Rsmostrar['user_nome']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Rsmostrar['user_nome']?></option>
    <?php
} while ($row_Rsmostrar = mysql_fetch_assoc($Rsmostrar));
  $rows = mysql_num_rows($Rsmostrar);
  if($rows > 0) {
  mysql_data_seek($Rsmostrar, 0);
  $row_Rsmostrar = mysql_fetch_assoc($Rsmostrar);
  }
?>

  • 1

    Maybe implementing jQuery-ui Autocomplete would be a good way out.

1 answer

0

1 question, Voce could use even Jquery UI, as @dvd said.

2 question, to pick up in descending order, make this logic

$listaUsuarios = //array de usuarios da tabela;

$amount = count($listaUsuarios); //quantidade de usuarios

for ($i = $amount; $i >= $amount; $i--) {
    //aqui voce faz a logica do <select>
    <option>
        echo $listaUsuarios[$i]; //vai fazer na ordem decrescente
    </option>
}

Just one logic, you implement your

Here is the Jquery UI: https://jqueryui.com/autocomplete/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.