How to display a list in alphabetical order from mysql table?

Asked

Viewed 182 times

-2

With this code the order of the letters menu, sent by mysql table, does not appear in alphabetical order. The order that currently appears is A D T V C S F M. Someone can help me to solve this problem; that is, by alphabetizing the list of letters?

Page home code:

<?php 
include 'conn.php';

$letter = mysqli_real_escape_string ($conn,htmlspecialchars(base64_decode($_GET["letter"])));

$sql = "SELECT Id,Palavra from dicionario_palavras where Pronta != 0 AND Palavra LIKE '".$letter."%'";

$result = $conn->query($sql);


$sql2 = "SELECT DISTINCT(SUBSTR(`Palavra`, 1, 1)) As abc from dicionario_palavras where Pronta != 0";

$result2 = $conn->query($sql2);

?>
  • Have you tried adding the order by in your SQL?

  • Yes I already have the order By well done: us_DefinicoesPalavras(asc).

  • Where is the ORDER BY in your query then ? I believe a ORDER BY Palavra ASC at the end of your query already solves the problem.

  • Ok Leo... already solved. Thank you very much for the tip. I published here below the solution.

1 answer

1

Just fix the initial code of the page at the end, already tested and works:

$sql2 = "SELECT DISTINCT(SUBSTR(`Palavra`, 1, 1)) As abc from dicionario_palavras where Pronta != 0 ORDER BY abc";

Wrong code:

$sql2 = "SELECT DISTINCT(SUBSTR(`Palavra`, 1, 1)) As abc from dicionario_palavras where Pronta != 0";

Browser other questions tagged

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