Receive all data from a table with only one query

Asked

Viewed 232 times

1

I am trying to create a system that uses Lastfm images. But I want to show only the images of the artists registered in the database. I did so:

  1. I made a bank query on condition that banda_id was not null.

  2. I created a foreach to get the data.

  3. I created another foreach inside the previous foreach taking the band name and setting to receive the API image.

Does it work? I say it does, too many consultations,but it was the only way to make it work.

I wanted to see with you guys, take all the data without I need to do "loop" to catch the data.

I’m open to suggestions to improve, almost sure I’m doing something wrong, so any help is welcome.

<?php

    $getPag = (!empty($Link->getLocal()[1]) ? $Link->getLocal()[1] : 0);
    $Pagina = new Pager(HOME . '/bandas/');
    $Pagina->ExePagina($getPag, 12);


    $lerbanda = new Ler;
    $lerbanda->ExeLer("ws_bands", "WHERE band_parent IS NOT NULL ORDER BY band_date DESC LIMIT :limit OFFSET :offset", "limit={$Pagina->getLimit()}&offset={$Pagina->getOffset()}");


    if (!$lerbanda->getResult()):
        $Pager->ReturnPage();
        WSErro("Desculpe, não existem bandas cadastradas no momento, favor volte mais tarde!", WS_INFOR);
    else:
            echo'<div class="banda_news">';
            echo'<div class="grid-row">';

            foreach ($lerbanda->getResult() as $banda):
                 echo "<img src=\"";
                 echo LastFMArtwork::getArtwork($banda['band_title'],true, "mega");
                 echo "\">";
            endforeach;

            echo '</div>';
            echo '</div>';

    endif;
    $Pagina->ExePaginar("ws_bands", "ORDER BY band_date");
    echo $Pagina->getPagina();

?>

API class

http://jonjones.org.uk/blog/getting-and-displaying-album-artwork-using-last-fm-api-in-php/

  • Put your code in so we can see

  • I took a look at the documentation and I couldn’t find a method of taking images of various bands. You could perform this query periodically, saving the images, as if it were a cache. I believe that the images do not change often

No answers

Browser other questions tagged

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