How to place the list of letters received from the database in a horizontal position and join it in a single page to the list of words of the searched letter

Asked

Viewed 57 times

3

I am building the database of a dictionary and I made the code of the page Indice.php that shows the letters of the alphabet:

a) The list appears vertically but I wanted to be horizontal.
b) How to join the list of letters and the list of words on the same page?

We can see here in these pages:

https://www.corampopulo.pt/login/dicionario-penal/indice.php
https://www.corampopulo.pt/login/dicionario-penal/lista.php

...

Follow the code on page 1...

<?php

    include 'conn.php';

    $sql = "SELECT DISTINCT(SUBSTR(`Palavra`, 1, 1)) As abc from Definicoes_palavras";

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

    ?>

    <!DOCTYPE html>
    <html lang="en">
      <head>
           <meta charset="utf-8">
    Indice das Letras
    <br/><br/>
    <?php 
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                ?>
                <a href='lista.php?letter=<?php echo base64_encode($row["abc"]); ?>'><? echo strtoupper($row["abc"]); ?></a><br/>
                <?
            }
        }
    ?>
    </body>
    </html>
    <?php

    $conn->close();

    ?>

Follow the code on page 2...

    <?php 
include 'conn.php';

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

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

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

?>
<!DOCTYPE html>
<html lang="en">
  <head>
       <meta charset="utf-8">
<h2>Letra <?php echo $letter;?> </h2>
<br/><br/>
 <a href="https://www.corampopulo.pt/login/dicionario-penal/indice.php">Voltar ao Índice</a>
                   <br> <br>

<h4>Seleccione um item da lista:</h4>

<?php 
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            ?>

             <a href='fundamentacao1.php?word=<?php echo base64_encode($row["Id"]); ?>'><? echo $row["Palavra"]; ?></a><br/>
            <?
        }
    }
?>
</body>
</html>

<?php

$conn->close();

?>

1 answer

4


For him to stand side by side you just take out the <br> of that line:

<a href='lista.php?letter=<?php echo base64_encode($row["abc"]); ?>'><? echo strtoupper($row["abc"]); ?></a><br/>

Staying that way:

<a href='lista.php?letter=<?php echo base64_encode($row["abc"]); ?>'><? echo strtoupper($row["abc"]); ?></a>

If you need to space the letters just add:

echo "&nbsp;";

at the end of the tag &nbsp is an HTML code for spacing

  • OK that’s right Luan Brito... another friend person had already explained to me almost at the same time of his post. But thank you in the same.

  • opa tranquil then beast

Browser other questions tagged

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