How to list BD query

Asked

Viewed 71 times

1

Good night!
How do I list a query in the database?
I have a bank where you store singers and their songs...
I wanted to list Spotify style, listing numerally according to the amount of content in the database.


inserir a descrição da imagem aqui

1 answer

1


I see my example in db:

inserir a descrição da imagem aqui

Code:

<?php
    $mysqli = new mysqli("host", "user", "senha", "db");

    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    $count = 1;

    if ($sth = $mysqli->query("SELECT * FROM artistas")){
        while ($row = $sth->fetch_assoc()){
            echo $count . " - " . $row['cantor'] . "<br>";
            $count++;
        }
    }

Upshot:

inserir a descrição da imagem aqui

  • It worked out buddy! Thank you very much...

  • @Victorfreitas I’m glad it worked, but I ask you to mark the answer as accepted so that others who have the problem can solve tb

Browser other questions tagged

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