There is a code. It performs a query from the database for all entries with pagination.

include('config.php'); $lim = "9"; @$page = $_GET['page']; $res = mysql_query("SELECT COUNT(*) FROM music"); $row = mysql_fetch_array($res); $posts = $row[0]; $str = ceil($posts / $lim); if (empty($page) or $page < 0) $page = 1; if ($page > $str) $page = $str; $start = $page * $lim - $lim; $result = mysql_query("SELECT * FROM music ORDER BY date DESC LIMIT $start, $lim"); $myrow = mysql_fetch_array($result); $artist = $myrow['artist']; do { printf(" <div id='mp3'> <h5 style='margin: 20px;'>" . $myrow['artist'] . " - " . $myrow['title'] . "<a href='" . $myrow['link'] . "'>Скачать</a></h5> </div> "); } while ($myrow = mysql_fetch_array($result)); echo '<div id="navi_n"><a href=?page=' . ($page - 1) . '>Назад</a> '; $i = 1; while ($i <= $str) { if ($i == $page) { echo '<strong><a href=?page=' . $i . '>' . $i . '</a></strong> '; } else { echo '<a href=?page=' . $i . '>' . $i . '</a> '; } $i = $i + 1; } echo ' <a href=?page=' . ($page + 1) . '>Вперед</a></div>'; 

I can not figure out how to make the artist field be a link, when clicked, the selection from the database was performed only by its name? It is also necessary to make a selection of records by month, i.e. the user clicks on "January" they are shown all the records for January, of course there is a date field. Already the third day I'm worried: (

update1: I do not know whose lesson :) Yes, an error. Just starting to recognize php, so there is no reason to smile: D

    1 answer 1

    create the file findmusic.php

     <?php if (!empty($_REQUEST['artist'])) { $mus_q = mysql_query("SELECT * FROM music WHERE artist='$_REQUEST[artist]'"); if($mus_q) { echo "<table border=1>"; echo "<tr><td>Артист</td><td>Песня</tr>"; // Так как запрос возвращает несколько строк, применяем цикл while($mus_art = mysql_fetch_array($mus_q)) { echo "<tr><td>".$mus_art['artist']."&nbsp;</td><td>".$mus_art['music']."</td></tr>"; } echo "</table>"; } else { echo "<p><b>Error: ".mysql_error()."</b><p>"; exit(); } } ?> 

    And in your file we change:

     <h5 style='margin: 20px;'><a href=\"findmusic.php?artist=\"" . $myrow['artist'] . " - " 
    • It is displayed, but all links lead to findmusic.php? Artist = :( - CryFiX
    • I gave you only an example of how to display information. Then it's up to you. But I will give a hint: You can output the request to your main file, and from there to do everything. - Dmitry Alekseevich
    • Understood, already trying. (: - CryFiX
    • Thank you, based on your script, but how to protect $ _GET in this case from entering any line, after? Artist =? How to make it so that it determines only those names that are in the database, and otherwise it gave out die? - CryFiX 2:58 pm
    • one
      @CryFiX it's time to turn on the brain and do everything yourself! - Palmervan